/// <summary> /// Function: Create a Strategy and run startup procedures /// </summary> /// <param name="name">name</param> /// <param name="ccy">base currency</param> /// <param name="initialDate">starting date</param> /// <param name="initialValue">starting NAV</param> /// <param name="simulated">false if persistent</param> new public static ConstantStrategy CreateStrategy(string name, Currency ccy, BusinessDay initialDate, double initialValue, bool simulated) { Instrument instrument = Instrument.CreateInstrument(name, InstrumentType.Strategy, name + "ConstantStrategy", ccy, FundingType.TotalReturn, simulated); ConstantStrategy strategy = ConstantStrategy.CreateStrategy(instrument, initialDate, 1); strategy.SetConstantCarryCost(0.0 / (double)10000.0, 0.0 / (double)10000.0, DayCountConvention.Act360, 360); strategy.TimeSeriesRoll = TimeSeriesRollType.Last; strategy.Initialize(); return(strategy); }
public static CashFlowGroup CreateStrategy(Instrument instrument, BusinessDay initialDate, double amount, BusinessDay startDate, BusinessDay endDate, InterestRateTenorType ttype, Portfolio parent) { if (instrument.InstrumentType == InstrumentType.Strategy) { CashFlowGroup Strategy = new CashFlowGroup(instrument); Strategy.TimeSeriesRoll = TimeSeriesRollType.Last; Strategy.Amount = amount; Strategy.StartDate = startDate.DateTime; Strategy.EndDate = endDate.DateTime; Strategy.Frequency = ttype; Portfolio portfolio = null; if (parent != null) { Instrument portfolio_instrument = Instrument.CreateInstrument(instrument.Name + "/Portfolio", InstrumentType.Portfolio, instrument.Name + "/Portfolio", instrument.Currency, FundingType.TotalReturn, instrument.SimulationObject); portfolio = Portfolio.CreatePortfolio(portfolio_instrument, parent.LongReserve, parent.ShortReserve, parent); portfolio.TimeSeriesRoll = TimeSeriesRollType.Last; foreach (Instrument reserve in parent.Reserves) { portfolio.AddReserve(reserve.Currency, parent.Reserve(reserve.Currency, PositionType.Long), parent.Reserve(reserve.Currency, PositionType.Short)); } if (parent.Strategy != null) { parent.Strategy.AddInstrument(Strategy, initialDate.DateTime); } } else { Currency main_currency = instrument.Currency; //ConstantStrategy main_cash_strategy = ConstantStrategy.CreateStrategy(instrument.Name + "/" + main_currency + "/Cash", main_currency, initialDate, 1.0, instrument.SimulationObject); Instrument main_cash_strategy = Instrument.FindInstrument(main_currency.Name + " - Cash"); Instrument portfolio_instrument = Instrument.CreateInstrument(instrument.Name + "/Portfolio", InstrumentType.Portfolio, instrument.Name + "/Portfolio", main_currency, FundingType.TotalReturn, instrument.SimulationObject); portfolio = Portfolio.CreatePortfolio(portfolio_instrument, main_cash_strategy, main_cash_strategy, parent); portfolio.TimeSeriesRoll = TimeSeriesRollType.Last; portfolio.AddReserve(main_currency, main_cash_strategy, main_cash_strategy); } portfolio.Strategy = Strategy; Strategy.GenerateCashFlows(initialDate.DateTime); double npv = Strategy.NPV(initialDate); Strategy.Startup(initialDate, npv, portfolio); Strategy.InitialDate = new DateTime(1990, 01, 06); double npv2 = Strategy.NPV(initialDate); // if (parent != null) // parent.CreatePosition(Strategy, initialDate.DateTime, (Strategy[initialDate.DateTime] == 0.0 ? 0 : 1.0), npv2); if (!instrument.SimulationObject) { Strategy.Portfolio.MasterPortfolio.Strategy.Tree.SaveNewPositions(); Strategy.Portfolio.MasterPortfolio.Strategy.Tree.Save(); } return(Strategy); } else { throw new Exception("Instrument not a Strategy"); } }
public static CashFlowGroup CreateCashFlowGroup(string name, Currency ccy, BusinessDay initialDate, double amount, BusinessDay startDate, BusinessDay endDate, InterestRateTenorType ttype, bool simulated, Portfolio parent) { Instrument instrument = Instrument.CreateInstrument(name, InstrumentType.Strategy, name, ccy, FundingType.TotalReturn, simulated); return(CreateStrategy(instrument, initialDate, amount, startDate, endDate, ttype, parent)); }
public static CashFlow CreateCashFlow(string name, Currency ccy, BusinessDay initialDate, double amount, BusinessDay date, CashFlowGroup group, bool simulated) { Instrument instrument = Instrument.CreateInstrument(name, InstrumentType.Strategy, name, ccy, FundingType.TotalReturn, simulated); return(CreateStrategy(instrument, initialDate, amount, date, group)); }