Пример #1
0
 def createBondAndEquityPortfolio(self):
     portfolio = Portfolio()
     position = EquityPosition.EquityPosition(95,'TEST1')
     portfolio.addPosition(position)
     position = BondPosition.BondPosition(100,'TEST1')
     portfolio.addPosition(position)
     return portfolio
Пример #2
0
    def testTEST1PortfolioTEST1EquityCorrelation(self):
        pricingDate = self.pricingDate
        QuantLib.Settings.instance().evaluationDate = pricingDate.ql()
        portfolio1 = Portfolio.objects.get(name='TEST1', user='******')
        modelPositions = portfolio1.modelposition_set.filter(asOf=pricingDate)
        for modelPosition in modelPositions:
            position = CreatePosition(modelPosition)
            portfolio1.addPosition(position)
#        for p in portfolio1.positions:
 #           print "************************************** %s" % str(p)

        timePeriods = VARUtilities.VARTimePeriodsAndSteps()
        timePeriods.generate(start = Date.Date(month=8,day=30,year=2011),
                             end = self.pricingDate,
                             num = 1, term = Enum.TimePeriod('D'), 
                             calendar = Calendar.US())
        analysis1 = HistoricalVAR.HistoricalVAR(pricingDate=pricingDate, 
                                                   portfolio=portfolio1, 
                                                   timeSteps=timePeriods,
                                                   confidenceInterval=0.95,
                                                   marketId='TEST1')
        analysis1.run()
        pnls1 = analysis1.getPnLList()
        portfolio2 = Portfolio()
        modelPosition = ModelPosition(portfolio=portfolio2,
                                      positionType=PositionType('EQUITY'),
                                      ticker='TEST1',
                                      amount=110,
                                      asOf=pricingDate)
        
        portfolio2.addPosition(CreatePosition(modelPosition))
        analysis2 = HistoricalVAR.HistoricalVAR(pricingDate=pricingDate, 
                                                   portfolio=portfolio2, 
                                                   timeSteps=timePeriods,
                                                   confidenceInterval=0.95,
                                                   marketId='TEST1')
        analysis2.run()
        pnls2 = analysis2.getPnLList()
#         print portfolio1.positions
#         print '********************************\n'
#         for p in portfolio1.positions:
#             print p
#         print '********************************\n'
#         print portfolio2.positions
#         for p in portfolio2.positions:
#             print p
#         print '********************************\n'
#        print pnls1
#        print pnls2
#        v1 = [pnl[1] for pnl in pnls1]
#        v2 = [pnl[1] for pnl in pnls2]
#        v1 = v1[1:]
#        v2 = v2[1:]
 #       print v1
  #      print v2
        pearsonCorr = pearsonr(pnls1,pnls2)
  #      print '3: ' + str(pearsonCorr[0])
        self.failIf(abs(0.655160228007 - pearsonCorr[0]) > 0.0000001, 
                    'Pearson Correlation for TEST1 portfolio vs TEST1 stock incorrect')
    def setupData(self):
        productionStartDate = Date(month=7,day=25,year=2013)
        lastLoadDate = Date(month=10,day=14,year=2013)
        loadDate = productionStartDate
        
        if not Location.objects.filter(name='Benchmark').exists():
            location = Location()
            location.name = 'Benchmark'
            location.pricingDate = date(month=10,day=14,year=2013)
            location.save()
        location = Location.objects.get(name='Benchmark')
            
        if not User.objects.filter(username='******').exists():
            user = User.objects.create_user(username='******',email='*****@*****.**',\
                                            password='******')
            user.is_staff = True
            user.is_superuser = True
            user.save()

        user1 = User.objects.get(username='******')
        if not UserProfile.objects.filter(user=user1).exists():
            up1 = UserProfile()
            up1.user = user1
            up1.location = location
            up1.marketId = 'EOD'
            up1.save()

        equities = Equity.objects.all()
        for equity in equities:
#            print equity
            if not Portfolio.objects.filter(name=equity.ticker, user='******').exists():
                portfolio =Portfolio()
                portfolio.name = equity.ticker
                portfolio.user = '******'
                portfolio.save()
            portfolio = Portfolio.objects.get(name=equity.ticker, user='******')
 
            timeSteps = VARUtilities.VARTimePeriodsAndSteps()
            timeSteps.generate(start=productionStartDate, end=lastLoadDate, num=1, 
                               term=Enum.TimePeriod('D'), calendar=Calendar.Target())
            for loadDate in timeSteps.timeSteps:
                if not ModelPosition.objects.filter(asOf=loadDate, portfolio=portfolio, 
                                                    positionType = Enum.PositionType('EQUITY'),
                                                    ticker = equity.ticker, amount = 100.0).exists():
                    position = ModelPosition()
                    position.asOf=loadDate
                    position.portfolio = portfolio
                    position.positionType = Enum.PositionType('EQUITY')
                    position.ticker = equity.ticker
                    position.amount = 100.0
                    position.save()
Пример #4
0
    def testOneBondAndOneEquity(self):
        marketDataContainer = MarketDataContainer.MarketDataContainer()
        stock = EquityPosition.EquityPosition(100,'TEST1')
        marketDataContainer.add(stock.marketData(pricingDate=self.pricingDate, marketId=self.marketId))
        stock.marketDataContainer = marketDataContainer
        bond = BondPosition.BondPosition(10000, 'TEST1')
        marketDataContainer.add(bond.marketData(self.pricingDate, self.marketId))
        bond.marketDataContainer = marketDataContainer
        portfolio = Portfolio()
        portfolio.addPosition(stock)
        portfolio.addPosition(bond)
#        print stock.NPV(self.pricingDate, self.marketId)
 #       print bond.NPV(self.pricingDate, self.marketId)
        #print round(portfolio.NPV(pricingDate=self.pricingDate, marketId=self.marketId),2)
        self.failIf(round(portfolio.NPV(pricingDate=self.pricingDate, marketId=self.marketId),2) <> 1012696.1)
Пример #5
0
    def test_company_has_portfolio(self):
        tech = Portfolio(name='tech')
        arbor = Company(name='Arbor Realty Trust',
                        symbol='ABR',
                        portfolio='low risk')

        assert seattle.portfolio.name == 'tech'
Пример #6
0
def portfolio(session):
    """
    """
    portfolio = Portfolio(name='Default', user_id=users.id)
    session.add(portfolio)
    session.commit()
    return portfolio
Пример #7
0
def portfolio(session, user):
    """Testable portfolio databse table."""
    portfolio = Portfolio(name='Default')

    session.add(portfolio)
    session.commit()

    return portfolio
Пример #8
0
 def test_co_has_port(self):
     red = Portfolio(name='red')
     cf = Company(
         name='Code Fellows',
         symbol='CF',
         exchange='Some Exchange',
         description='We learn more faster',
         portfolio=red
     )
     assert cf.portfolio.name == 'red'
Пример #9
0
def main():
    print 'Start'
    pricingDate = Date(month=9, day=12, year=2011)
    portfolio =Portfolio()
    QuantLib.Settings.instance().evaluationDate = pricingDate.ql()
    pos1 = BondPosition(100, 'TEST1')
    pos2 = EquityPosition(100,'TEST1')
    portfolio.addPosition(pos1)
    portfolio.addPosition(pos2)
    timePeriods = VARUtilities.VARTimePeriodsAndSteps()
    timePeriods.generate(start=Date(month=8,day=30,year=2011), 
                         end=Date(month=9,day=12,year=2011), num=1, 
                         term=TimePeriod('D').ql(), 
                         calendar=Calendar.US())
    #print 'timePeriods: ' + str(timePeriods)
    analysis = HistoricalVAR(pricingDate=pricingDate, portfolio=portfolio, timeSteps=timePeriods, 
                               confidenceInterval=0.95, marketId='TEST1')

    print 'HVaR = %f' % analysis.run()
    print 'End'
Пример #10
0
 def testOneBondAndOneEquityOver10Days(self):
     portfolio = Portfolio()
     portfolio.addPosition(BondPosition.BondPosition(100,'TEST1'))
     portfolio.addPosition(EquityPosition.EquityPosition(100,'TEST1'))
     pricingDate = self.pricingDate
     QuantLib.Settings.instance().evaluationDate = pricingDate.ql()
     timePeriods = VARUtilities.VARTimePeriodsAndSteps()
     timePeriods.generate(start = Date.Date(month=8,day=30,year=2011),
                          end = self.pricingDate,
                          num = 1, term = Enum.TimePeriod('D'), 
                          calendar = Calendar.US())
     analysis = HistoricalVAR.HistoricalVAR(pricingDate=pricingDate, 
                                                portfolio=portfolio, 
                                                timeSteps=timePeriods,
                                                confidenceInterval=0.95,
                                                marketId='TEST1')
 #    print '3: ' + str(analysis.run())
     #Ballpark test only. The value makes sense but not exactly reconciled
     self.failIf(abs(-0.0510159444181-analysis.run()) > 0.0000001, 
                 'Historical VaR result for TEST1 over 10 days incorrect')
Пример #11
0
 def test_port_has_co(self):
     blue = Portfolio(name='blue')
     cf = Company(
         name='Code Fellows',
         symbol='CF',
         exchange='Some Exchange',
         description='We learn more faster',
         portfolio=blue
     )
     fc = Company(
         name='Mirror Universe Code Fellows',
         symbol='FC',
         exchange='Exchange Some',
         description='We forget less slower',
         portfolio=blue
     )
     assert blue.companies[0].symbol == 'CF'
     assert blue.companies[1].symbol == 'FC'
Пример #12
0
def portfolio(session, user):
    # company = Company(name = 'Default',  portfolio_id =authenticated_client.id,company_sym = 'MSFT', website = 'www.microsoft.com', sector = 'TECH', industry = 'PROGRAMMING')
    portfolio = Portfolio(name='Default', user_id=user.id)
    session.add(portfolio)
    session.commit()
    return portfolio
Пример #13
0
    def test_portfolio_has_symbols(self):
        tech = Portfolio(name='tech')
        adt = Company(name='ADT Inc.', symbol='adt', category=tech)

        assert tech.companies[0].name == 'ADT Inc.'
Пример #14
0
def portfolio(session, user):
    portfolio = Portfolio(name='test_portfolio', user=user)
    session.add(portfolio)
    session.commit()
    return portfolio
Пример #15
0
    def dataForProductionStart(self): 
        #Setup initial data for Tim's portfolios as of 7/24/13        
        productionStartDate = Date(month=7,day=25,year=2013)
        
        if not Batch.objects.filter(batchDate=productionStartDate):
            batch = Batch()
            batch.batchDate = productionStartDate
            batch.save()
        
        if not Location.objects.filter(name='Manhasset').exists():
            location = Location()
            location.name = 'Manhasset'
            location.pricingDate = date(month=7,day=25,year=2013)
            location.save()
        
        if not User.objects.filter(username='******').exists():
            #Enter email password
            User.objects.create_user(username='******',email='*****@*****.**',\
                                     password='******')
            
        cmt = User.objects.get(username='******')
        if not UserProfile.objects.filter(user=cmt).exists():
            up2 = UserProfile()
            up2.user = cmt
            up2.location = Location.objects.get(name='Manhasset')
            up2.marketId = 'EOD'
            up2.save()
        #if it exists then make sure Location is Manhasset
        else:
            profile = UserProfile.objects.get(user=cmt)
            profile.location = Location.objects.get(name='Manhasset')
            profile.marketId = 'EOD'
            profile.save()

        #Setup portfolios
        portfolioData = (['401K','cmt'],['ChaseIRA','cmt'],
                         ['TDIRA','cmt'],['TDPostTaxIRA','cmt'],
                         ['Just2Trade','cmt'],['TDEmergency','cmt'])
        for p in portfolioData:
            if not Portfolio.objects.filter(name=p[0],user=p[1]):
                portfolio =Portfolio()
                portfolio.name = p[0]
                portfolio.user = p[1]
                portfolio.save()

        #Setup Equities and Prices as of productionStartDate
        dataSet = (('NEIAX',32.57),('PTTDX',10.78),('EFA',61.06),
                   ('GSG',32.67),('SAN-E',26.7301),('VWO',40.19),
                   ('VNQ', 71.17))
        for data in dataSet:
            if not Equity.objects.filter(ticker=data[0]).exists():
                equity = Equity()
                equity.ticker = data[0]
                equity.assetType = Enum.AssetType('EQUITYUS')
                equity.save()
            equity = Equity.objects.get(ticker=data[0])
            stockPrice = StockPrice()
            stockPrice.equity = equity
            stockPrice.pricingDate = productionStartDate
            stockPrice.marketId = 'EOD'
            stockPrice.mid = data[1]
            stockPrice.save()

        #Setup Bond identifiers and TCBonds as of productionStartDate
        dataSet = (('PortAuth_4.00_JAN42','73358WGG3',Date(month=1,day=15,year=2012),Date(month=1,day=15,year=2042),0.04,),)
        for data in dataSet:
            if not Identifier.objects.filter(name=data[1],type=BondIdentifierType('CUSIP')):
                identifier = Identifier()
                identifier.name = data[1]
                identifier.type = BondIdentifierType('CUSIP')
                identifier.save()
        for data in dataSet:
            if not TCBond.objects.filter(name=data[0]):
                tcBond = TCBond()
                tcBond.name = data[0]
                tcBond.identifiers = Identifier.objects.get(name=data[1],type=BondIdentifierType('CUSIP'))
                tcBond.startDate = data[2].toPythonDate()
                tcBond.endDate = data[3].toPythonDate()
                tcBond.coupon = data[4]
                tcBond.assetType = Enum.AssetType('NYMUNIBOND')
                tcBond.save()
 
        #Setup OAS for production start date
        if not BondOAS.objects.filter(tCBond=TCBond.objects.get(name='PortAuth_4.00_JAN42'), marketId='EOD',pricingDate=productionStartDate):
            bondOAS = BondOAS(tCBond=TCBond.objects.get(name='PortAuth_4.00_JAN42'), marketId='EOD',pricingDate=productionStartDate,mid=0.014)
            bondOAS.save()
            
        #Setup Rates
        fredLoader = FREDLoader.FREDLoader()
        fredLoader.loadLiborCurvesForSpecificDates(marketId='EOD', datesToLoadFor=[productionStartDate])
       
        #Setup transactions 
        dataSet = (('401K','INIT','EQUITY','NEIAX',8758.407),
                    ('401K','INIT','EQUITY','PTTDX',10746.441),
                    ('ChaseIRA','INIT','EQUITY','EFA',633.37038),
                    ('TDIRA','INIT','EQUITY','EFA',47),
                    ('TDIRA','INIT','EQUITY','GSG',610),
                    ('TDIRA','INIT','EQUITY','VWO',1050),
                    ('TDIRA','INIT','CASH','Cash',11151.23),
                    ('TDPostTaxIRA','INIT','EQUITY','EFA',560),
                    ('TDPostTaxIRA','INIT','EQUITY','VNQ',170),
                    ('TDPostTaxIRA','INIT','CASH','Cash',951.33),
                    ('Just2Trade','INIT','EQUITY','GSG',300),
                    ('Just2Trade','INIT','EQUITY','VWO',430),
                    ('TDEmergency','INIT','BOND','PortAuth_4.00_JAN42',100),
                    ('TDEmergency','INIT','CASH','Cash',201.01))
        
        for data in dataSet:
            if not Transaction.objects.filter(portfolio=Portfolio.objects.get(name=data[0]),
                                              transactionType=TransactionType(data[1]),
                                              positionType=PositionType(data[2]),
                                              ticker=data[3],
                                              amount=data[4],
                                              transactionDate = productionStartDate,
                                              effectiveDate = productionStartDate):
                transaction = Transaction()
                transaction.portfolio =Portfolio.objects.get(name=data[0])
                transaction.transactionType = TransactionType(data[1])
                transaction.positionType = PositionType(data[2])
                transaction.ticker = data[3]
                transaction.amount = data[4]
                transaction.transactionDate = productionStartDate
                transaction.effectiveDate = productionStartDate
                transaction.reflectedInPosition = False
                transaction.save()
Пример #16
0
    def dataForSuccessfulTest(self):
        '''
        This saves all data so that system tests run successfully
        Pricing date is 9/12/2011 with market data id TEST1
        '''
        testDatePython = date(month=9,day=12,year=2011)
        testDate = Date(month=9,day=12,year=2011)
        testFirstDate = Date(month=8,day=30,year=2011)
        
        if not Location.objects.filter(name='Test1').exists():
            location = Location()
            location.name = 'Test1'
            location.pricingDate = date(month=9,day=12,year=2011)
            location.save()
        location = Location.objects.get(name='Test1')
            
        if not User.objects.filter(username='******').exists():
            user = User.objects.create_user(username='******',email='*****@*****.**',\
                                            password='******')
            user.is_staff = True
            user.is_superuser = True
            user.save()

        if not User.objects.filter(username='******').exists():
            User.objects.create_user(username='******',email='*****@*****.**',\
                                     password='******')

        if not User.objects.filter(username='******').exists():
            User.objects.create_user(username='******',email='*****@*****.**',\
                                     password='******')

        if not User.objects.filter(username='******').exists():
            User.objects.create_user(username='******',email='*****@*****.**',\
                                     password='******')

        user1 = User.objects.get(username='******')
        if not UserProfile.objects.filter(user=user1).exists():
            up1 = UserProfile()
            up1.user = user1
            up1.location = location
            up1.marketId = 'EOD'
            up1.save()
            
        user2 = User.objects.get(username='******')
        if not UserProfile.objects.filter(user=user2).exists():
            up2 = UserProfile()
            up2.user = user2
            up2.location = location
            up2.marketId = 'EOD'
            up2.save()

        user3 = User.objects.get(username='******')
        if not UserProfile.objects.filter(user=user3).exists():
            up3 = UserProfile()
            up3.user = user3
            up3.location = location
            up3.marketId = 'TEST1'
            up3.save()

        user4 = User.objects.get(username='******')
        if not UserProfile.objects.filter(user=user4).exists():
            up4 = UserProfile()
            up4.user = user4
            up4.location = location
            up4.marketId = 'DEMO'
            up4.save()
        
        if not TCBond.objects.filter(name='TEST1').exists():
            bond = TCBond()
            bond.name = 'TEST1'
            bond.ccy = 'USD'
            cusip = Enum.BondIdentifierType('CUSIP') 
            if not Identifier.objects.filter(name='123456789', type=cusip):
                identifier = Identifier()
                identifier.name='123456789'
                identifier.type=cusip
                identifier.save()
            identifier = Identifier.objects.get(name='123456789', type=cusip)  
            bond.identifiers = identifier
            bond.startDate = Date(month=9,day=12,year=2010).toPythonDate()
            bond.endDate = Date(month=9,day=12,year=2020).toPythonDate()
            bond.coupon = 0.01
            bond.basis = '30360'
            bond.paymentFrequency = Enum.Frequency('S')
            bond.paymentRollRule = Enum.Roll('MF')
            bond.paymentCalendar = Calendar.createCalendar('US')
            bond.assetType = Enum.AssetType('NYMUNIBOND')
            bond.save()

        if not Equity.objects.filter(ticker='TEST1').exists():
            equity = Equity()
            equity.ticker = 'TEST1'
            equity.assetType = Enum.AssetType('EQUITYUS')
            equity.save()
        equity = Equity.objects.get(ticker='TEST1')
        stockPrice = StockPrice()
        stockPrice.equity = equity
        stockPrice.pricingDate = testDate
        stockPrice.marketId = 'TEST1'
        stockPrice.mid = 123.45
        stockPrice.save()
        equity = Equity.objects.get(ticker='TEST1')
        stockPrice = StockPrice()
        stockPrice.equity = equity
        stockPrice.pricingDate = testFirstDate
        stockPrice.marketId = 'TEST1'
        stockPrice.mid = 123.44
        stockPrice.save()
        if not Equity.objects.filter(ticker='TEST2').exists():
            equity = Equity()
            equity.ticker = 'TEST2'
            equity.assetType = Enum.AssetType('EQUITYUS')
            equity.save()
        equity = Equity.objects.get(ticker='TEST2')
        stockPrice = StockPrice()
        stockPrice.equity = equity
        stockPrice.pricingDate = testDate
        stockPrice.marketId = 'TEST1'
        stockPrice.mid = 543.21
        stockPrice.save()
        equity = Equity.objects.get(ticker='TEST2')
        stockPrice = StockPrice()
        stockPrice.equity = equity
        stockPrice.pricingDate = testFirstDate
        stockPrice.marketId = 'TEST1'
        stockPrice.mid = 543.11
        stockPrice.save()
        
        if not Portfolio.objects.filter(name='TEST1', user='******').exists():
            portfolio =Portfolio()
            portfolio.name = 'TEST1'
            portfolio.user = '******'
            portfolio.save()
        portfolio =Portfolio.objects.get(name='TEST1', user='******')
        
        if not ModelPosition.objects.filter(asOf=testDate, portfolio=portfolio, 
                                       positionType = Enum.PositionType('EQUITY'),
                                       ticker = 'TEST1', amount = 100.0).exists():
            position = ModelPosition()
            position.asOf=testDate
            position.portfolio = portfolio
            position.positionType = Enum.PositionType('EQUITY')
            position.ticker = 'TEST1'
            position.amount = 100.0
            position.save()

        if not ModelPosition.objects.filter(asOf=testDate, portfolio=portfolio, 
                                       positionType = Enum.PositionType('EQUITY'),
                                       ticker = 'TEST2', amount = 100.0).exists():
            position = ModelPosition()
            position.asOf=testDate
            position.portfolio = portfolio
            position.positionType = Enum.PositionType('EQUITY')
            position.ticker = 'TEST2'
            position.amount = 100.0
            position.save()

        if not ModelPosition.objects.filter(asOf=testDate, portfolio=portfolio, 
                                       positionType = Enum.PositionType('BOND'),
                                       ticker = 'TEST1', amount = 100.0).exists():
            position = ModelPosition()
            position.asOf=testDate
            position.portfolio = portfolio
            position.positionType = Enum.PositionType('BOND')
            position.ticker = 'TEST1'
            position.amount = 100.0
            position.save()
       
        if not ModelPosition.objects.filter(asOf=testFirstDate, portfolio=portfolio, 
                                       positionType = Enum.PositionType('EQUITY'),
                                       ticker = 'TEST1', amount = 100.0).exists():
            position = ModelPosition()
            position.asOf=testFirstDate
            position.portfolio = portfolio
            position.positionType = Enum.PositionType('EQUITY')
            position.ticker = 'TEST1'
            position.amount = 100.0
            position.save()

        if not ModelPosition.objects.filter(asOf=testFirstDate, portfolio=portfolio, 
                                       positionType = Enum.PositionType('EQUITY'),
                                       ticker = 'TEST2', amount = 100.0).exists():
            position = ModelPosition()
            position.asOf=testFirstDate
            position.portfolio = portfolio
            position.positionType = Enum.PositionType('EQUITY')
            position.ticker = 'TEST2'
            position.amount = 100.0
            position.save()

        if not ModelPosition.objects.filter(asOf=testFirstDate, portfolio=portfolio, 
                                       positionType = Enum.PositionType('BOND'),
                                       ticker = 'TEST1', amount = 100.0).exists():
            position = ModelPosition()
            position.asOf=testFirstDate
            position.portfolio = portfolio
            position.positionType = Enum.PositionType('BOND')
            position.ticker = 'TEST1'
            position.amount = 100.0
            position.save()
            
        if not ModelPosition.objects.filter(asOf=testFirstDate, portfolio=portfolio, 
                                       positionType = Enum.PositionType('CASH'),
                                       ticker = 'Cash', amount = 1000.0).exists():
            position = ModelPosition()
            position.asOf=testFirstDate
            position.portfolio = portfolio
            position.positionType = Enum.PositionType('CASH')
            position.ticker = 'Cash'
            position.amount = 1000.0
            position.save()
            
        curve = InterestRateCurve()
        curve.ccy = 'USD'
        curve.index = Enum.Index('LIBOR')
        curve.term = Enum.TimePeriod('M')
        curve.numTerms = 3
        curve.pricingDate =testDate
        curve.marketId = 'TEST1'

        curve.addRate(InterestRate(type='Deposit', term=Enum.TimePeriod('M'),
                                   numTerms=1,mid=0.01,curve=curve))
        curve.addRate(InterestRate(type='Deposit', term=Enum.TimePeriod('M'),
                                   numTerms=3,mid=0.01,curve=curve))
        curve.addRate(InterestRate(type='Swap', term=Enum.TimePeriod('Y'),
                                   numTerms=1,mid=0.01,curve=curve))
        curve.addRate(InterestRate(type='Swap', term=Enum.TimePeriod('Y'),
                                   numTerms=5,mid=0.01,curve=curve))
        curve.addRate(InterestRate(type='Swap', term=Enum.TimePeriod('Y'),
                                   numTerms=10,mid=0.01,curve=curve))
        curve.addRate(InterestRate(type='Swap', term=Enum.TimePeriod('Y'),
                                   numTerms=30,mid=0.01,curve=curve))
        curve.save()

        curve = InterestRateCurve()
        curve.ccy = 'USD'
        curve.index = Enum.Index('LIBOR')
        curve.term = Enum.TimePeriod('M')
        curve.numTerms = 3
        curve.pricingDate = testFirstDate
        curve.marketId = 'TEST1'

        curve.addRate(InterestRate(type='Deposit', term=Enum.TimePeriod('M'),
                                   numTerms=1,mid=0.01,curve=curve))
        curve.addRate(InterestRate(type='Deposit', term=Enum.TimePeriod('M'),
                                   numTerms=3,mid=0.01,curve=curve))
        curve.addRate(InterestRate(type='Swap', term=Enum.TimePeriod('Y'),
                                   numTerms=1,mid=0.01,curve=curve))
        curve.addRate(InterestRate(type='Swap', term=Enum.TimePeriod('Y'),
                                   numTerms=5,mid=0.01,curve=curve))
        curve.addRate(InterestRate(type='Swap', term=Enum.TimePeriod('Y'),
                                   numTerms=10,mid=0.01,curve=curve))
        curve.addRate(InterestRate(type='Swap', term=Enum.TimePeriod('Y'),
                                   numTerms=30,mid=0.01,curve=curve))
        curve.save()
        
        if not SwaptionVolatilitySurface.objects.filter(ccy=Enum.Currency('USD'), index=Enum.Index('LIBOR'), term=Enum.TimePeriod('M'), numTerms=3, 
                                                        pricingDate=testDate, marketId='TEST1'):
            #Special case where I just append the vols. Should use a function
            vols = SwaptionVolatilitySurface(ccy=Enum.Currency('USD'), index=Enum.Index('LIBOR'), term=Enum.TimePeriod('M'), numTerms=3, 
                                             pricingDate=testDate, marketId='TEST1')
            volPoints = []
            volPoints.append(SwaptionVolatility(expiryTerm=Enum.TimePeriod('Y'), expiryNumTerms=1, underlyingTerm=Enum.TimePeriod('Y'),
                                                underlyingNumTerms=3, mid=0.40, surface=vols))
            volPoints.append(SwaptionVolatility(expiryTerm=Enum.TimePeriod('Y'), expiryNumTerms=3, underlyingTerm=Enum.TimePeriod('Y'),
                                                underlyingNumTerms=3, mid=0.45, surface=vols))
            volPoints.append(SwaptionVolatility(expiryTerm=Enum.TimePeriod('Y'), expiryNumTerms=1, underlyingTerm=Enum.TimePeriod('Y'),
                                                underlyingNumTerms=5, mid=0.5, surface=vols))
            volPoints.append(SwaptionVolatility(expiryTerm=Enum.TimePeriod('Y'), expiryNumTerms=3, underlyingTerm=Enum.TimePeriod('Y'),
                                                underlyingNumTerms=5, mid=0.55, surface=vols))
            vols.addVolatilities(volPoints)
            vols.save()
            
        if not BondOAS.objects.filter(tCBond=TCBond.objects.get(name='TEST1'),pricingDate=testDate,
                                   marketId='TEST1'):
            bondOAS = BondOAS(tCBond=TCBond.objects.get(name='TEST1'),pricingDate=testDate,
                              marketId='TEST1',mid=0.0012)
            bondOAS.save()
        #done for only one test BondPositionTest.testLoadAndSaveMarketData
        if not BondOAS.objects.filter(tCBond=TCBond.objects.get(name='TEST1'),pricingDate=Date(month=1,day=1,year=2009),
                                      marketId='EOD'):
            bondOAS = BondOAS(tCBond=TCBond.objects.get(name='TEST1'),pricingDate=Date(month=1,day=1,year=2009),
                              marketId='EOD',mid=0.01)
            bondOAS.save()
        #now load zero oas for all dates we do testing
        timePeriods = VARUtilities.VARTimePeriodsAndSteps()
        timePeriods.generate(start = Date(month=8,day=30,year=2011), end = Date(month=9,day=12,year=2011), 
                             num = 1, term = Enum.TimePeriod('D'), calendar = Calendar.US())
        for timeStep in timePeriods.timeSteps:
            if not BondOAS.objects.filter(tCBond=TCBond.objects.get(name='TEST1'), pricingDate=timeStep, marketId='TEST1'):
                bondOAS = BondOAS(tCBond=TCBond.objects.get(name='TEST1'), pricingDate=timeStep, marketId='TEST1',mid=0.0)
                bondOAS.save()
        
        fileLoader = MarketDataLoader.EquityPriceLoader()
        fileLoader.loadStockPriceFromCSVFile(ROOT_PATH+'/misc/data/StockPricesForHVaRTests.csv')
        fileLoader.loadInterestRateFromCSVFile(ROOT_PATH+'/misc/data/InterestRatesForHVaRTests.csv')

        if not HvarConfiguration.objects.filter(name='TEST1').exists():
            config = HvarConfiguration()
            config.name = 'TEST1'
            config.startDate = Date(month=8,day=30,year=2011).toPythonDate()
            config.endDate = Date(month=9,day=12,year=2011).toPythonDate()
            config.stepSize = 1
            config.stepUnit = Enum.TimePeriod('D')
            config.calendar = Calendar.US()
            config.confLevel = 0.95
            config.marketId = 'TEST1'
            config.save()