O'Reilly logo

Modeling Maximum Trading Profits with C++ by Valerii Salov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CHAPTER 6

Best to Better

Now we have everything ready to squeeze out additional profits from a potential profit strategy. This chapter presents two profit-and-loss reserve algorithms and a program computing the market offer. Forward!

ALGORITHM FOR THE FIRST PROFIT-AND-LOSS RESERVE STRATEGY

The natural input for building the first and second profit-and-loss (P&L) reserve strategies includes vectors of prices P and costs C, initial margin M, maintenance margin Mm, and the initial number of contracts traded U. It is simpler, however, to build both strategies assuming that a potential profit strategy Upps and its initial cash balance A0 are known in advance. The function potential_profit_min_account_alg previously described helps us get both items. Given the vectors P, C, Upps, and values A0, M, and Mm, the following steps represent the first algorithm:

  1. Scan Upps and find the first buy or sell action. This is the market entry point. The absolute value of this action is U. If the action is found and U ≠ 0, then go to the step 2. If no such action is found, then the first P&L reserve strategy is a “do nothing” strategy. Return the value zero and STOP.
  2. Depending on the sign of the first action, enter a long or short position with U contracts at the current price. Record this action in a collector, which has been initially filled by zeros, for the first P&L reserve strategy. Reduce the initial cash balance A0 by the current cost times U (the total transaction cost). Go to step 3.
  3. Continue ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required