|  |  | @ -48,7 +48,7 @@ export async function backtest({ | 
			
		
	
		
		
			
				
					
					|  |  |  |             ...calendar, |  |  |  |             ...calendar, | 
			
		
	
		
		
			
				
					
					|  |  |  |           }, |  |  |  |           }, | 
			
		
	
		
		
			
				
					
					|  |  |  |           date, |  |  |  |           date, | 
			
		
	
		
		
			
				
					
					|  |  |  | 				}), |  |  |  |         }) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |       ); |  |  |  |       ); | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |     // for each minute of that day for which we have a stock candlestick:
 |  |  |  |     // for each minute of that day for which we have a stock candlestick:
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -57,12 +57,12 @@ export async function backtest({ | 
			
		
	
		
		
			
				
					
					|  |  |  |       // filter-out calendars that are far-from-the-money (10%)
 |  |  |  |       // filter-out calendars that are far-from-the-money (10%)
 | 
			
		
	
		
		
			
				
					
					|  |  |  |       const calendarsNearTheMoney = calendars.filter( |  |  |  |       const calendarsNearTheMoney = calendars.filter( | 
			
		
	
		
		
			
				
					
					|  |  |  |         ({ strike }) => |  |  |  |         ({ strike }) => | 
			
		
	
		
		
			
				
					
					|  |  |  | 					Math.abs((stockAggregate.open - strike) / stockAggregate.open) < 0.1, |  |  |  |           Math.abs((stockAggregate.open - strike) / stockAggregate.open) < 0.1 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |       ); |  |  |  |       ); | 
			
		
	
		
		
			
				
					
					|  |  |  |       // for each relevant calendar on that day:
 |  |  |  |       // for each relevant calendar on that day:
 | 
			
		
	
		
		
			
				
					
					|  |  |  |       for (const calendar of calendarsNearTheMoney) { |  |  |  |       for (const calendar of calendarsNearTheMoney) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         const strikePercentageFromTheMoney = Math.abs( |  |  |  |         const strikePercentageFromTheMoney = Math.abs( | 
			
		
	
		
		
			
				
					
					|  |  |  | 					(stockAggregate.open - calendar.strike) / stockAggregate.open, |  |  |  |           (stockAggregate.open - calendar.strike) / stockAggregate.open | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         ); |  |  |  |         ); | 
			
		
	
		
		
			
				
					
					|  |  |  |         /** In days. */ |  |  |  |         /** In days. */ | 
			
		
	
		
		
			
				
					
					|  |  |  |         const calendarSpan = |  |  |  |         const calendarSpan = | 
			
		
	
	
		
		
			
				
					|  |  | @ -78,14 +78,14 @@ export async function backtest({ | 
			
		
	
		
		
			
				
					
					|  |  |  |           }); |  |  |  |           }); | 
			
		
	
		
		
			
				
					
					|  |  |  |         const calendarAggregates = calendarsAggregates.get(calendar); |  |  |  |         const calendarAggregates = calendarsAggregates.get(calendar); | 
			
		
	
		
		
			
				
					
					|  |  |  |         const calendarAggregateAtCurrentTime = calendarAggregates.find( |  |  |  |         const calendarAggregateAtCurrentTime = calendarAggregates.find( | 
			
		
	
		
		
			
				
					
					|  |  |  | 					({ tsStart }) => tsStart === stockAggregate.tsStart, |  |  |  |           ({ tsStart }) => tsStart === stockAggregate.tsStart | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         ); |  |  |  |         ); | 
			
		
	
		
		
			
				
					
					|  |  |  |         // if there exists a matching calendar candlestick for the current minute:
 |  |  |  |         // if there exists a matching calendar candlestick for the current minute:
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (calendarAggregateAtCurrentTime) { |  |  |  |         if (calendarAggregateAtCurrentTime) { | 
			
		
	
		
		
			
				
					
					|  |  |  |           // if the current candlestick is a good price (i.e. less than the target price):
 |  |  |  |           // if the current candlestick is a good price (i.e. less than the target price):
 | 
			
		
	
		
		
			
				
					
					|  |  |  |           const minCalendarPriceInCandlestick = Math.min( |  |  |  |           const minCalendarPriceInCandlestick = Math.min( | 
			
		
	
		
		
			
				
					
					|  |  |  |             calendarAggregateAtCurrentTime.open, |  |  |  |             calendarAggregateAtCurrentTime.open, | 
			
		
	
		
		
			
				
					
					|  |  |  | 						calendarAggregateAtCurrentTime.close, |  |  |  |             calendarAggregateAtCurrentTime.close | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |           ); |  |  |  |           ); | 
			
		
	
		
		
			
				
					
					|  |  |  |           if ( |  |  |  |           if ( | 
			
		
	
		
		
			
				
					
					|  |  |  |             minCalendarPriceInCandlestick < targetCalendarPrice && |  |  |  |             minCalendarPriceInCandlestick < targetCalendarPrice && | 
			
		
	
	
		
		
			
				
					|  |  | @ -104,7 +104,7 @@ export async function backtest({ | 
			
		
	
		
		
			
				
					
					|  |  |  |                 minCalendarPriceInCandlestick * 100, |  |  |  |                 minCalendarPriceInCandlestick * 100, | 
			
		
	
		
		
			
				
					
					|  |  |  |                 "...$", |  |  |  |                 "...$", | 
			
		
	
		
		
			
				
					
					|  |  |  |                 buyingPower, |  |  |  |                 buyingPower, | 
			
		
	
		
		
			
				
					
					|  |  |  | 								"left", |  |  |  |                 "left" | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |               ); |  |  |  |               ); | 
			
		
	
		
		
			
				
					
					|  |  |  |               didBuyCalendar = true; |  |  |  |               didBuyCalendar = true; | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
	
		
		
			
				
					|  |  | @ -136,7 +136,7 @@ export async function backtest({ | 
			
		
	
		
		
			
				
					
					|  |  |  |           calendarClosingPrice, |  |  |  |           calendarClosingPrice, | 
			
		
	
		
		
			
				
					
					|  |  |  |           "...$", |  |  |  |           "...$", | 
			
		
	
		
		
			
				
					
					|  |  |  |           buyingPower, |  |  |  |           buyingPower, | 
			
		
	
		
		
			
				
					
					|  |  |  | 					"left", |  |  |  |           "left" | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         ); |  |  |  |         ); | 
			
		
	
		
		
			
				
					
					|  |  |  |       } |  |  |  |       } | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
	
		
		
			
				
					|  |  | 
 |