Skip to content

Commit

Permalink
Merge commit '9e949c004fbf9712984593816525d2776351b791'
Browse files Browse the repository at this point in the history
# Conflicts:
#	.gitignore
  • Loading branch information
Nachiappan committed Jan 1, 2020
2 parents 65ca12d + 9e949c0 commit 54347c6
Show file tree
Hide file tree
Showing 47 changed files with 1,436 additions and 1,075 deletions.
62 changes: 34 additions & 28 deletions Simplify/Simplify.sln
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Simplify", "Simplify\Simplify.csproj", "{9F7856E7-43ED-44C4-8423-8A3A0DA4FA4C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimplifyUi", "SimplifyUi\SimplifyUi.csproj", "{F203A336-E547-4351-8E9D-0037946EA882}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9F7856E7-43ED-44C4-8423-8A3A0DA4FA4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9F7856E7-43ED-44C4-8423-8A3A0DA4FA4C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9F7856E7-43ED-44C4-8423-8A3A0DA4FA4C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9F7856E7-43ED-44C4-8423-8A3A0DA4FA4C}.Release|Any CPU.Build.0 = Release|Any CPU
{F203A336-E547-4351-8E9D-0037946EA882}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F203A336-E547-4351-8E9D-0037946EA882}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F203A336-E547-4351-8E9D-0037946EA882}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F203A336-E547-4351-8E9D-0037946EA882}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Simplify", "Simplify\Simplify.csproj", "{9F7856E7-43ED-44C4-8423-8A3A0DA4FA4C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimplifyUi", "SimplifyUi\SimplifyUi.csproj", "{F203A336-E547-4351-8E9D-0037946EA882}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimplifyUiComponents", "SimplifyUiComponents\SimplifyUiComponents.csproj", "{839D5617-DCB7-4E79-A52F-C0D7BFBF3817}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9F7856E7-43ED-44C4-8423-8A3A0DA4FA4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9F7856E7-43ED-44C4-8423-8A3A0DA4FA4C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9F7856E7-43ED-44C4-8423-8A3A0DA4FA4C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9F7856E7-43ED-44C4-8423-8A3A0DA4FA4C}.Release|Any CPU.Build.0 = Release|Any CPU
{F203A336-E547-4351-8E9D-0037946EA882}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F203A336-E547-4351-8E9D-0037946EA882}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F203A336-E547-4351-8E9D-0037946EA882}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F203A336-E547-4351-8E9D-0037946EA882}.Release|Any CPU.Build.0 = Release|Any CPU
{839D5617-DCB7-4E79-A52F-C0D7BFBF3817}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{839D5617-DCB7-4E79-A52F-C0D7BFBF3817}.Debug|Any CPU.Build.0 = Debug|Any CPU
{839D5617-DCB7-4E79-A52F-C0D7BFBF3817}.Release|Any CPU.ActiveCfg = Release|Any CPU
{839D5617-DCB7-4E79-A52F-C0D7BFBF3817}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,9 @@ public class EffectiveCostRecord
public void Write(string fileName, ProcessedTradeStatementsContainer container)
{
ExcelWriter writer = new ExcelWriter(fileName);
WriteAssetNames(container, writer);
WriteSumary(container, writer);
WriteProfitBook(container, writer);
WriteOpenPositions(container, writer);
WriteEffectiveCostBook(container, writer);
}

private void WriteOpenPositions(ProcessedTradeStatementsContainer container, ExcelWriter writer)
Expand All @@ -117,14 +115,7 @@ public List<TradeStatement> ReadTradeLog(ILogger logger, string fileName, string
var tradeLogGateway = new TradeLogGateway();
return tradeLogGateway.ReadTradeLog(logger,fileName, sheetName);
}

private static void WriteEffectiveCostBook(ProcessedTradeStatementsContainer container, ExcelWriter writer)
{
var effectiveCostStatements = container.EffectiveCostStatementBook
.Select(x => new EffectiveCostRecord {Name = x.Name, Cost = x.AverageCost}).ToList();
writer.AddSheet("EffectiveCost", effectiveCostStatements);
}


private static void WriteProfitBook(ProcessedTradeStatementsContainer container, ExcelWriter writer)
{
var profitBookRecords = container.ProfitBook.Select((x, i) => new ProfitBookRecord
Expand Down Expand Up @@ -171,12 +162,7 @@ private static void WriteSumary(ProcessedTradeStatementsContainer container, Exc
}).ToList();
writer.AddSheet("Summary", summaryRecords);
}

private static void WriteAssetNames(ProcessedTradeStatementsContainer container, ExcelWriter writer)
{
var assetNameRecords = container.AssetNamesBook.Select(x => new AssetNameRecord {Name = x}).ToList();
writer.AddSheet("AssetName", assetNameRecords);
}

}

public class TradeLogGateway
Expand Down
7 changes: 4 additions & 3 deletions Simplify/Simplify/Simplify.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,16 @@
<Compile Include="Trade\AssetEvaluationAggregatedStatement.cs" />
<Compile Include="Trade\AssetEvaluationStatement.cs" />
<Compile Include="Trade\AssetEvalutionBook.cs" />
<Compile Include="Trade\AssetQuotation.cs" />
<Compile Include="Trade\AssetStatement.cs" />
<Compile Include="Trade\ClosedAssetSummaryBook.cs" />
<Compile Include="Trade\CostStatement.cs" />
<Compile Include="Application\JournalStatementBracketTrimmer.cs" />
<Compile Include="Application\RealBooksGenerator.cs" />
<Compile Include="Application\StatementPriorityAdjuster.cs" />
<Compile Include="Trade\PurchasedAssetEvaluationStatement.cs" />
<Compile Include="Trade\PurchasedAssetEvaluationSummarizedStatement.cs" />
<Compile Include="Trade\QuotationRepository.cs" />
<Compile Include="Trade\QuotationStatement.cs" />
<Compile Include="Trade\OpenAssetSummaryBook.cs" />
<Compile Include="Trade\SquarableStatement.cs" />
<Compile Include="Books\NotionalAccount.cs" />
<Compile Include="Books\NotionalAccountBook.cs" />
Expand All @@ -93,7 +94,7 @@
<Compile Include="Books\DatedStatement.cs" />
<Compile Include="Books\DetailedDatedStatement.cs" />
<Compile Include="Books\RealAccountBook.cs" />
<Compile Include="Trade\Internal\StatementsSeparator.cs" />
<Compile Include="Trade\Internal\SaleAndPurchaseMapper.cs" />
<Compile Include="Trade\TradeStatement.cs" />
<Compile Include="DataGateway\IBooksOfAccountWriter.cs" />
<Compile Include="ExcelDataGateway\BalanceSheetGateway.cs" />
Expand Down
26 changes: 26 additions & 0 deletions Simplify/Simplify/Trade/AssetQuotation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;

namespace Simplify.Trade
{
public class AssetQuotation
{
public event Action Changed;

private readonly Quote _quote;

public AssetQuotation(Quote quote)
{
_quote = quote;
_quote.Changed += () => Changed?.Invoke();
}

public string Name { get; set; }
public bool IsOwned { get; set; }

public double? QuotePerUnit
{
get { return _quote.QuotedValue; }
set { _quote.QuotedValue = value; }
}
}
}
8 changes: 0 additions & 8 deletions Simplify/Simplify/Trade/CostStatement.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,45 @@

namespace Simplify.Trade
{
public class StatementsSeparator
public class SaleAndPurchaseMapper
{
public List<TradeStatement> OpenPositionBook { get; private set; }
public List<SquarableStatement> ProfitBook { get; set; }

public void SeparateStatementsAsClosedAndOpen(List<TradeStatement> statements, out List<TradeStatement> openStatements, out List<SquarableStatement> closedStatements)
{
OpenPositionBook = new List<TradeStatement>();
ProfitBook = new List<SquarableStatement>();
SeparateStatementsAsClosedAndOpen(statements);
openStatements = OpenPositionBook;
closedStatements = ProfitBook;
}

private void SeparateStatementsAsClosedAndOpen(List<TradeStatement> tradeStatements)
public List<SquarableStatement> MapSaleAndPurchaseStatements(List<TradeStatement> tradeStatements)
{
var assetNames = tradeStatements.Select(x => x.Name).Distinct().OrderBy(x => x).ToList();

foreach (var name in assetNames)
{
ProcessTradeStatements(tradeStatements.Where(x => x.Name == name).ToList());
}
var assetNames = tradeStatements.Select(x => x.Name).Distinct().OrderBy(x => x).ToList();
var profitBook = new List<SquarableStatement>();
foreach (var name in assetNames)
{
profitBook.AddRange(MapSaleAndPurchaseStatementsForOneAsset(tradeStatements.Where(x => x.Name == name).ToList()));
}
return profitBook;
}

private void ProcessTradeStatements(List<TradeStatement> tradeStatements)
{
private List<SquarableStatement> MapSaleAndPurchaseStatementsForOneAsset(List<TradeStatement> tradeStatements)
{
var profitBook = new List<SquarableStatement>();
var purchaseStatements = tradeStatements.Where(x => x.IsPurchase).OrderBy(x => x.Date).ToList();
var saleStatements = tradeStatements.Where(x => !x.IsPurchase).OrderBy(x => x.Date).ToList();
while (purchaseStatements.Any() && saleStatements.Any())
{
var squaredAndRemaining = SquareStatements(
RemoveFirstItem(purchaseStatements),
RemoveFirstItem(saleStatements));

ProfitBook.Add(squaredAndRemaining.SquarableStatement);
var squaredAndRemaining = SquareStatements(
RemoveFirstItem(purchaseStatements),
RemoveFirstItem(saleStatements));

profitBook.Add(squaredAndRemaining.SquarableStatement);
var remaining = squaredAndRemaining.RemainingTradeStatement;
if (remaining == null) continue;
if (remaining.IsPurchase)
purchaseStatements.Insert(0, remaining);
else
saleStatements.Insert(0, remaining);
}
if (purchaseStatements.Any())
OpenPositionBook.AddRange(purchaseStatements);
if (saleStatements.Any())
OpenPositionBook.AddRange(saleStatements);
if (purchaseStatements.Any())
profitBook.AddRange(purchaseStatements.Select(x => new SquarableStatement(x)));
if (saleStatements.Any())
profitBook.AddRange(saleStatements.Select(x => new SquarableStatement(x)));


return profitBook;
}

private TradeStatement RemoveFirstItem(IList<TradeStatement> statements)
Expand All @@ -73,7 +66,7 @@ private SquarableStatementAndRemainder SquareStatements(TradeStatement ts1, Trad
}

var brokenStatements = new BrokenTradeStatements(bigger, smaller.Quantity);
var squarableStatement = new SquarableStatement(new[] { brokenStatements.BrokenTradeStatement, smaller });
var squarableStatement = new SquarableStatement( brokenStatements.BrokenTradeStatement, smaller );
return new SquarableStatementAndRemainder(squarableStatement, brokenStatements.RemainingTradeStatement);
}

Expand Down
48 changes: 0 additions & 48 deletions Simplify/Simplify/Trade/OpenAssetSummaryBook.cs

This file was deleted.

Loading

0 comments on commit 54347c6

Please sign in to comment.