Beispiel #1
0
def allocation(request, portfolio, is_sample, read_only):
  refresh_positions(portfolio)
  
  positions = latest_positions(portfolio)
  _decorate_positions_for_display(positions, False)
  
  context = { 
      'positions': positions, 
      'current_tab' : 'allocation',
    }
  
  return render_page('allocation.html', request, portfolio = portfolio, extra_dictionary = context)
Beispiel #2
0
def income(request, portfolio, is_sample, read_only):
  transactions = Transaction.objects.filter(portfolio__id__exact = portfolio.id).order_by('-as_of_date', '-id')
  refresh_positions(portfolio, transactions)
  
  positions = latest_positions(portfolio)
  _decorate_positions_for_display(positions, request.GET.get("showClosedPositions", False))
  
  summary_map = {}
  for position in positions:
    summary_map[position.symbol] = IncomeSummary(position.symbol, position.market_value, position.cost_basis, position.pl, position.pl_percent, position.realized_pl, position.show)
  
  total_summary = IncomeSummary('*TOTAL*', 0.0, 0.0, 0.0, 0.0, 0.0, True)
  for transaction in transactions:
    if transaction.type != 'ADJUST':
      continue
    
    symbol = transaction.linked_symbol
    if symbol == None or symbol == '':
      symbol = transaction.symbol
      
    summary = summary_map.get(symbol)
    summary.add_income(transaction.as_of_date, transaction.total)
    
    if summary.show:
      total_summary.add_income(transaction.as_of_date, transaction.total)
    
  summaries = sorted(summary_map.values(), key = (lambda summary: summary.symbol))
  
  for summary in summaries:
      total_summary.market_value = total_summary.market_value + summary.market_value
      total_summary.cost_basis = total_summary.cost_basis + summary.cost_basis
      total_summary.unrealized_pl = total_summary.unrealized_pl + summary.unrealized_pl
      total_summary.realized_pl = total_summary.realized_pl + summary.realized_pl
  
  total_summary.unrealized_pl_percent = ((total_summary.market_value / total_summary.cost_basis) - 1) * 100
  
  context = {
      'read_only' : read_only,
      'summaries': summaries,
      'total_summary' : total_summary,
      'current_tab' : 'income',
    }

  return render_page('income.html', request, portfolio = portfolio, extra_dictionary = context)
Beispiel #3
0
def positions(request, portfolio, is_sample, read_only):
  
  transactions = Transaction.objects.filter(portfolio__id__exact = portfolio.id).order_by('-as_of_date', '-id')
  refresh_positions(portfolio, transactions)
  
  positions = latest_positions(portfolio)
  _decorate_positions_for_display(positions, request.GET.get("showClosedPositions", False))
  _decorate_positions_with_lots(positions)
  summary = _get_summary(positions, transactions)
  performance_history = _get_performance_history(portfolio, DAYS_IN_PERFORMANCE_HISTORY)
  
  context = {
      'read_only' : read_only, 
      'is_sample' : is_sample, 
      'positions': positions, 
      'summary' : summary, 
      'current_tab' : 'positions',
      'performance_history' : performance_history, 
      'benchmark_symbol' : PERFORMANCE_BENCHMARK_SYMBOL,
    }
  
  return render_page('positions.html', request, portfolio = portfolio, extra_dictionary = context)