Quantitative research or backtest requires masses of historical data. When it comes to test a strategy on equities, adjusted stock prices would be more preferrable in order to have an accurate profit and loss, without adjusting position and the parameters of the model.
One of my data collection program, which automatically fetches data from Bloomberg using its API, supports getting adjusted prices. There are only three lines of code that enable this feature, with setting three parameters
Bear in mind that...
adjustmentSplitshould be explicitly set to
falseif you want original stock price.
Here is my implementation of P&L calculation for real-time marketdata and trade log streaming, as you can see from the two member functions:
- The traded quantity is a signed number: positive for buy and negative for sell. That means the net position is negative if the transactioin short sells some products.
- If the trade feed takes close action, need to be careful of whether the close quantity is larger than the net position. In this case, the average open price should also be updated to the close price.
PnlSnapshotclass for a product:
In C++, it is a good practice to evaluate if the passed instance is exactly itself at the very beginning of defining a operator= method:...
Price calculation is an essential part of online stores. The value of a price changes under various conditions, such as adding tips, some percentages off, or tax refund. It is usually re-calculated in run-time once online customers select different plans or purchase extra services. In this sense, a dynamic calculator that is flexible enough to be called by client programmers is appealing.
Air ticket is a typical example. The price at first sight is a raw price, remaining to be updated by adding tax, insurance, etc. In essence, adding features to a price acts like extending properties or methods to an object. Using prototype chain can accomplish it. The code below defines some features at the outset. These “features” can be easily integrated into an existing object by a shared method: addFeature(), which creates a new object inherited from the existing object. ...
Objectis basically a factory pattern that generates different types of variables. See the code below:
Magic is real!...
In order to load a collection of external js files by this manner, I wrote a simple loader that takes an array of filenames, in which the js files are parsed and executed in order. ...
constructorproperty could be very useful when the type of an variable needs to be identified. In constructing a class and its instance, or even establishing inheritance by using prototypes,
constructordeserves more attention because it can be changed by default or by you.
An instance never has a
constructorproperty unless it is manually given. When the
constructorof an instance is accessed, it is traced in the whole prototype chain.
If there is no any prototype chain manually attached to the function (class), the
constructorof an instance is the class itself.
However, if the function’
prototypeobject is enriched, the instance’s
constructoris changed. ...
Compressed script files are essential components to a website with high performance. This is extremely true for single-page web apps that strongly rely on a bunch of js files.
I wrote jcompressor, a node package that is capable of compressing all .js files in a folder. With just several hits you can build all .js files in minimal size for production environment at ease. Check out jcompressor on GitHub: jcompressor....
I tried to use npm to install a node module globally on Ubuntu. Some errors occurred and I found the major reason was that the version of node.js was a bit too old. Fortunately, it is quite straightforward to update node.js. In Terminal issue the following command lines:...
Consulting the article here, I made a summary about the principles used to release the allocated memory. There are three major criteria for judging if a variable can be destroyed, indicating different number of variables whose memory should be collected.
slice()method, while arrays and strings do. Employing
callcan easily make
slice()work for objects, e.g.
Array.prototype.slice.call(arguments, 1), which is a commonly used manner to cope with the
argumentsobject in a function. However, the following usage is a bit weird:
When executing the codes wrapped in...
object’s scope on the top of the scope chain while the activation object and global object following. The codes below demonstrate how the program operates under the scope chain.
So what is the exact reason behind? Some programmers might argue that it is because the anonymous functions do not share the same scope with the global environment outside, so the variable name defined outside is invisible to the anonymous function here. It is not true. The codes below prove my answer. ...