Lean
$LEAN_TAG$
|
Time helper class collection for working with trading dates More...
Classes | |
struct | DateTimeWithZone |
Live charting is sensitive to timezone so need to convert the local system time to a UTC and display in browser as UTC. More... | |
class | MonthYearJsonConverter |
Helper method to deserialize month/year More... | |
Static Public Member Functions | |
static TimeSpan | GetNextLiveAuxiliaryDataDueTime () |
Helper method to get the new live auxiliary data due time More... | |
static TimeSpan | GetNextLiveAuxiliaryDataDueTime (DateTime utcNow) |
Helper method to get the new live auxiliary data due time More... | |
static int | GetSecondUnevenWait (int waitTimeMillis) |
Helper method to adjust a waiting time, in milliseconds, so it's uneven with the second turn around More... | |
static int | GetSecondUnevenWait (this DateTime now, int waitTimeMillis) |
Helper method to adjust a waiting time, in milliseconds, so it's uneven with the second turn around More... | |
static DateTime | UnixTimeStampToDateTime (double unixTimeStamp) |
Create a C# DateTime from a UnixTimestamp More... | |
static DateTime | UnixTimeStampToDateTime (decimal unixTimeStamp) |
Create a C# DateTime from a UnixTimestamp More... | |
static DateTime | UnixTimeStampToDateTime (long unixTimeStamp) |
Create a C# DateTime from a UnixTimestamp More... | |
static DateTime | UnixMillisecondTimeStampToDateTime (decimal unixTimeStamp) |
Create a C# DateTime from a UnixTimestamp More... | |
static DateTime | UnixNanosecondTimeStampToDateTime (long unixTimeStamp) |
Create a C# DateTime from a UnixTimestamp More... | |
static double | DateTimeToUnixTimeStamp (DateTime time) |
Convert a Datetime to Unix Timestamp More... | |
static double | DateTimeToUnixTimeStampMilliseconds (DateTime time) |
Convert a Datetime to Unix Timestamp More... | |
static long | DateTimeToUnixTimeStampNanoseconds (DateTime time) |
Convert a Datetime to Unix Timestamp More... | |
static double | TimeStamp () |
Get the current time as a unix timestamp More... | |
static TimeSpan | Max (TimeSpan one, TimeSpan two) |
Returns the timespan with the larger value More... | |
static TimeSpan | Min (TimeSpan one, TimeSpan two) |
Returns the timespan with the smaller value More... | |
static DateTime | Max (DateTime one, DateTime two) |
Returns the larger of two date times More... | |
static DateTime | Min (DateTime one, DateTime two) |
Returns the smaller of two date times More... | |
static TimeSpan | Multiply (this TimeSpan interval, double multiplier) |
Multiplies the specified interval by the multiplier More... | |
static DateTime | ParseDate (string dateToParse) |
Parse a standard YY MM DD date into a DateTime. Attempt common date formats More... | |
static DateTime | ParseFIXUtcTimestamp (string dateToParse) |
Parse a standard YY MM DD date into a DateTime. Attempt common date formats More... | |
static IEnumerable< DateTime > | DateTimeRange (DateTime from, DateTime thru, TimeSpan step) |
Define an enumerable date time range using the given time step More... | |
static IEnumerable< DateTime > | EachDay (DateTime from, DateTime thru) |
Define an enumerable date range and return each date as a datetime object in the date range More... | |
static IEnumerable< DateTime > | EachTradeableDay (ICollection< Security > securities, DateTime from, DateTime thru) |
Define an enumerable date range of tradeable dates - skip the holidays and weekends when securities in this algorithm don't trade. More... | |
static IEnumerable< DateTime > | EachTradeableDay (Security security, DateTime from, DateTime thru, bool extendedMarketHours=false) |
Define an enumerable date range of tradeable dates - skip the holidays and weekends when securities in this algorithm don't trade. More... | |
static IEnumerable< DateTime > | EachTradeableDay (SecurityExchangeHours exchange, DateTime from, DateTime thru, bool extendedMarketHours=false) |
Define an enumerable date range of tradeable dates - skip the holidays and weekends when securities in this algorithm don't trade. More... | |
static IEnumerable< DateTime > | EachTradeableDayInTimeZone (SecurityExchangeHours exchange, DateTime from, DateTime thru, DateTimeZone timeZone, bool includeExtendedMarketHours=true) |
Define an enumerable date range of tradeable dates but expressed in a different time zone. More... | |
static bool | TradableDate (IEnumerable< Security > securities, DateTime day) |
Make sure this date is not a holiday, or weekend for the securities in this algorithm. More... | |
static int | TradeableDates (ICollection< Security > securities, DateTime start, DateTime finish) |
Could of the number of tradeable dates within this period. More... | |
static DateTime | GetStartTimeForTradeBars (SecurityExchangeHours exchangeHours, DateTime end, TimeSpan barSize, int barCount, bool extendedMarketHours, DateTimeZone dataTimeZone, bool dailyPreciseEndTime=false) |
Determines the start time required to produce the requested number of bars and the given size More... | |
static DateTime | GetEndTimeForTradeBars (SecurityExchangeHours exchangeHours, DateTime start, TimeSpan barSize, int barCount, bool extendedMarketHours) |
Determines the end time at which the requested number of bars of the given will have elapsed. NOTE: The start time is not discretized by barSize units like is done in GetStartTimeForTradeBars More... | |
static int | GetNumberOfTradeBarsInInterval (SecurityExchangeHours exchangeHours, DateTime start, DateTime end, TimeSpan barSize) |
Gets the number of trade bars of the specified barSize that fit between the start and end More... | |
static double | NormalizeInstantWithinRange (DateTime start, DateTime current, TimeSpan period) |
Normalizes the current time within the specified period time = start => 0 time = start + period => 1 More... | |
static double | NormalizeTimeStep (TimeSpan period, TimeSpan stepSize) |
Normalizes the step size as a percentage of the period. More... | |
static TimeSpan | Abs (this TimeSpan timeSpan) |
Gets the absolute value of the specified time span More... | |
Static Public Attributes | |
static readonly DateTime | EndOfTime = new DateTime(2050, 12, 31) |
Provides a value far enough in the future the current computer hardware will have decayed :) More... | |
static TimeSpan | EndOfTimeTimeSpan = new TimeSpan(EndOfTime.Ticks) |
Provides a time span based on EndOfTime More... | |
static readonly DateTime | Start = new DateTime(1998, 1, 2) |
Provides a common and normalized start time for Lean data More... | |
static readonly DateTime | BeginningOfTime = DateTime.FromOADate(0) |
Provides a value far enough in the past that can be used as a lower bound on dates, 12/30/1899 More... | |
static readonly TimeSpan | MaxTimeSpan = TimeSpan.FromDays(1000*365) |
Provides a value large enough that we won't hit the limit, while small enough we can still do math against it without checking everywhere for TimeSpan.MaxValue More... | |
static readonly TimeSpan | OneYear = TimeSpan.FromDays(365) |
One Year TimeSpan Period Constant More... | |
static readonly TimeSpan | OneDay = TimeSpan.FromDays(1) |
One Day TimeSpan Period Constant More... | |
static readonly TimeSpan | OneHour = TimeSpan.FromHours(1) |
One Hour TimeSpan Period Constant More... | |
static readonly TimeSpan | OneMinute = TimeSpan.FromMinutes(1) |
One Minute TimeSpan Period Constant More... | |
static readonly TimeSpan | OneSecond = TimeSpan.FromSeconds(1) |
One Second TimeSpan Period Constant More... | |
static readonly TimeSpan | OneMillisecond = TimeSpan.FromMilliseconds(1) |
One Millisecond TimeSpan Period Constant More... | |
Properties | |
static TimeSpan | LiveAuxiliaryDataOffset = TimeSpan.FromHours(8) [get, set] |
Allows specifying an offset to trigger the tradable date event More... | |
|
static |
|
static |
|
static |
Helper method to adjust a waiting time, in milliseconds, so it's uneven with the second turn around
waitTimeMillis | The desired wait time |
This is useful for real time performance in live trading. We want to avoid adding unnecessary cpu usage, during periods where we know there will be cpu time demand, like a second turn around where data is emitted.
Definition at line 179 of file Time.cs.
|
static |
Helper method to adjust a waiting time, in milliseconds, so it's uneven with the second turn around
now | The current time |
waitTimeMillis | The desired wait time |
This is useful for real time performance in live trading. We want to avoid adding unnecessary cpu usage, during periods where we know there will be cpu time demand, like a second turn around where data is emitted.
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
Define an enumerable date range and return each date as a datetime object in the date range
from | DateTime start date |
thru | DateTime end date |
Definition at line 501 of file Time.cs.
|
static |
Define an enumerable date range of tradeable dates - skip the holidays and weekends when securities in this algorithm don't trade.
securities | Securities we have in portfolio |
from | Start date |
thru | End date |
Definition at line 514 of file Time.cs.
|
static |
Define an enumerable date range of tradeable dates - skip the holidays and weekends when securities in this algorithm don't trade.
security | The security to get tradeable dates for |
from | Start date |
thru | End date |
extendedMarketHours | True to include days with extended market hours only, like sunday for futures |
Definition at line 534 of file Time.cs.
|
static |
Define an enumerable date range of tradeable dates - skip the holidays and weekends when securities in this algorithm don't trade.
exchange | The security to get tradeable dates for |
from | Start date |
thru | End date |
extendedMarketHours | True to include days with extended market hours only, like sunday for futures |
Definition at line 547 of file Time.cs.
|
static |
Define an enumerable date range of tradeable dates but expressed in a different time zone.
This is mainly used to bridge the gap between exchange time zone and data time zone for file written to disk. The returned enumerable of dates is guaranteed to be the same size or longer than those generated via EachTradeableDay(ICollection<Security>,DateTime,DateTime)
exchange | The exchange hours |
from | The start time in the exchange time zone |
thru | The end time in the exchange time zone (inclusive of the final day) |
timeZone | The timezone to project the dates into (inclusive of the final day) |
includeExtendedMarketHours | True to include extended market hours trading in the search, false otherwise |
Definition at line 571 of file Time.cs.
|
static |
Make sure this date is not a holiday, or weekend for the securities in this algorithm.
securities | Security manager from the algorithm |
day | DateTime to check if trade-able. |
Definition at line 605 of file Time.cs.
|
static |
|
static |
Determines the start time required to produce the requested number of bars and the given size
exchangeHours | The exchange hours used to test for market open hours |
end | The end time of the last bar over the requested period |
barSize | The length of each bar |
barCount | The number of bars requested |
extendedMarketHours | True to allow extended market hours bars, otherwise false for only normal market hours |
dataTimeZone | Timezone for this data |
dailyPreciseEndTime | True if daily strict end times are enabled |
Definition at line 661 of file Time.cs.
|
static |
Determines the end time at which the requested number of bars of the given will have elapsed. NOTE: The start time is not discretized by barSize units like is done in GetStartTimeForTradeBars
exchangeHours | The exchange hours used to test for market open hours |
start | The end time of the last bar over the requested period |
barSize | The length of each bar |
barCount | The number of bars requested |
extendedMarketHours | True to allow extended market hours bars, otherwise false for only normal market hours |
Definition at line 710 of file Time.cs.
|
static |
Gets the number of trade bars of the specified barSize that fit between the start and end
exchangeHours | The exchange used to test for market open hours |
start | The start time of the interval in the exchange time zone |
end | The end time of the interval in the exchange time zone |
barSize | The step size used to count number of bars between start and end |
Definition at line 752 of file Time.cs.
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
staticgetset |