def test_parse_file(self):
        parser = CSVOrderParser("data/SimpleOrdersFile.csv")
        parser.parse()

        orders = parser.get_parsed_orders()

        symbols = parser.get_symbols_traded()

        self.assertEqual(len(symbols), 2)
        self.assertTrue("AAPL" in symbols)
        self.assertTrue("IBM" in symbols)

        first_trade, last_trade = parser.get_dates_range()
        self.assertEqual("2011-01-10", first_trade.strftime("%Y-%m-%d"))
        self.assertEqual("2011-01-13", last_trade.strftime("%Y-%m-%d"))

        self.assertEqual(len(orders), 3)

        self.assertEqual(orders[0].symbol, "AAPL")
        self.assertEqual(orders[0].type, Order.TYPE_BUY)
        self.assertEqual(orders[0].quantity,1500)
        self.assertEqual(orders[0].timestamp.strftime("%Y-%m-%d %H:%M:%S"),"2011-01-10 16:00:00")

        self.assertEqual(orders[1].symbol, "AAPL")
        self.assertEqual(orders[1].type, Order.TYPE_SELL)
        self.assertEqual(orders[1].quantity,1500)
        self.assertEqual(orders[1].timestamp.strftime("%Y-%m-%d %H:%M:%S"),"2011-01-13 16:00:00")

        self.assertEqual(orders[2].symbol, "IBM")
        self.assertEqual(orders[2].type, Order.TYPE_BUY)
        self.assertEqual(orders[2].quantity,4000)
        self.assertEqual(orders[2].timestamp.strftime("%Y-%m-%d %H:%M:%S"),"2011-01-13 16:00:00")
    def test_parse_file(self):
        parser = CSVOrderParser("data/SimpleOrdersFile.csv")
        parser.parse()

        orders = parser.get_parsed_orders()

        symbols = parser.get_symbols_traded()

        self.assertEqual(len(symbols), 2)
        self.assertTrue("AAPL" in symbols)
        self.assertTrue("IBM" in symbols)

        first_trade, last_trade = parser.get_dates_range()
        self.assertEqual("2011-01-10", first_trade.strftime("%Y-%m-%d"))
        self.assertEqual("2011-01-13", last_trade.strftime("%Y-%m-%d"))

        self.assertEqual(len(orders), 3)

        self.assertEqual(orders[0].symbol, "AAPL")
        self.assertEqual(orders[0].type, Order.TYPE_BUY)
        self.assertEqual(orders[0].quantity, 1500)
        self.assertEqual(orders[0].timestamp.strftime("%Y-%m-%d %H:%M:%S"),
                         "2011-01-10 16:00:00")

        self.assertEqual(orders[1].symbol, "AAPL")
        self.assertEqual(orders[1].type, Order.TYPE_SELL)
        self.assertEqual(orders[1].quantity, 1500)
        self.assertEqual(orders[1].timestamp.strftime("%Y-%m-%d %H:%M:%S"),
                         "2011-01-13 16:00:00")

        self.assertEqual(orders[2].symbol, "IBM")
        self.assertEqual(orders[2].type, Order.TYPE_BUY)
        self.assertEqual(orders[2].quantity, 4000)
        self.assertEqual(orders[2].timestamp.strftime("%Y-%m-%d %H:%M:%S"),
                         "2011-01-13 16:00:00")
    def setUp(self):
        parser = CSVOrderParser("data/SimpleOrdersFile.csv")
        parser.parse()
        orders = parser.get_parsed_orders()
        start_date, end_date = parser.get_dates_range()

        self.market = Market(parser.get_symbols_traded(),start_date,end_date)
        self.portfolio = Portfolio(self.market, 1000000)
        for order in orders:
            self.portfolio.add_order(order)

        self.portfolio.calculate_number_of_shares_held()
        self.portfolio.calculate_portfolio_value()

        self.portfolio_report = PortfolioReport(self.portfolio)
    def setUp(self):
        parser = CSVOrderParser("data/SimpleOrdersFile.csv")
        parser.parse()
        orders = parser.get_parsed_orders()
        start_date, end_date = parser.get_dates_range()

        self.market = Market(parser.get_symbols_traded(), start_date, end_date)
        self.portfolio = Portfolio(self.market, 1000000)
        for order in orders:
            self.portfolio.add_order(order)

        self.portfolio.calculate_number_of_shares_held()
        self.portfolio.calculate_portfolio_value()

        self.portfolio_report = PortfolioReport(self.portfolio)
Exemple #5
0
from backtesting.Portfolio import Portfolio
from backtesting.Report.PortfolioReport import PortfolioReport
import matplotlib.pyplot as plt
import pylab

#A simple program used to run and play around with
#Portfolio and Market
#Plots value of all holdings

order_parser = CSVOrderParser("test/data/SimpleOrdersFile.csv")
order_parser.parse()

start_date, end_date = order_parser.get_dates_range()
market = Market(order_parser.get_symbols_traded(), start_date, end_date)

portfolio = Portfolio(market, 1000000)

for order in order_parser.get_parsed_orders():
    portfolio.add_order(order)

portfolio.execute()
portfolio.calculate_portfolio_value()

report = PortfolioReport(portfolio)
print report.get_return()

figure = plt.figure()

figure.axes.append(portfolio.holdings_value_sum.plot())

pylab.show()
Exemple #6
0
from backtesting.Portfolio import Portfolio
from backtesting.Report.PortfolioReport import PortfolioReport
import matplotlib.pyplot as plt
import pylab

#A simple program used to run and play around with
#Portfolio and Market
#Plots value of all holdings

order_parser = CSVOrderParser("test/data/SimpleOrdersFile.csv")
order_parser.parse()

start_date, end_date = order_parser.get_dates_range()
market = Market(order_parser.get_symbols_traded(),start_date,end_date)

portfolio = Portfolio(market, 1000000)

for order in order_parser.get_parsed_orders():
    portfolio.add_order(order)

portfolio.execute()
portfolio.calculate_portfolio_value()

report = PortfolioReport(portfolio)
print report.get_return()

figure = plt.figure()

figure.axes.append(portfolio.holdings_value_sum.plot())

pylab.show()