defined majority of optimization algorithm

master
Brian Sakal 3 years ago
parent 174e66e36d
commit 7152d0423b

@ -1,9 +1,27 @@
/*
Collect contiguous ranges. These are where the underlying is expected to be at the front-month.
For each strike in the contiguous ranges, collect all front-month/back-month combinations
For each of these front-month/back-month combinations, calculate PNL (by %-return) assuming the underlying is at each strike in the contiguous ranges
For each of these potential underlying close-prices, choose the best front-month/back-month combo.
For each ...
Start with an empty array of calendars (the "position"). (The array will contain the final, optimized position.)
Starting at the leftmost strike that's within the user-defined spot-price range, find the cheapest (though not necessarily most capital-efficient) front-month/back-month combo, and append it to the calendar-array.
Check profitability, as follows:
Check profitability assuming the underlying expires at the leftmost spot-price of the leftmost range. The next spot-prices to check are at the strikes _within_ the range, followed by the rightmost spot-price of the range; followed by doing the same for the rest of the ranges.
If, at "expiration" (i.e. the front-month), the position is profitable at this spot-price [*1]:
If there are more spot-prices to check to the right of this one:
Check the next spot-price.
Else (i.e. if there are _not_ more spot-prices to check to the right of this one):
That means we're "covered". Return position.
Else (i.e. if, at expiration, the position is _not_ profitable at this spot-price):
Try to shift the rightmost calendar to the right (regardless of whether it's towards or away from the current spot-price) by one strike.
Check profitability starting from the leftmost spot-price-at-expiration, up to and including the spot-price we're currently evaluating:
If the tweaked position is profitable at this spot-price:
If we're holding by the spot-price we're currently evaluating:
Keep the tweaked position, and continue with it as we would with a "profitable-thus-far" position (i.e. [*1]).
Else (i.e. if we're _not yet_ holding by the spot-price we're currently evaluating):
Continue checking with the next spot-price.
Else (i.e. if the tweaked position is _not_ profitable at this spot-price):
If we're holding by the spot-price we're currently evaluating:
Shift, by one more strike, the rightmost calendar in the position.
Else if we're holding by the
*/
export const calculateBestCombinationOfCalendars(){

Loading…
Cancel
Save