-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic activity pnl in attribution for MC
- Loading branch information
1 parent
9ea83f4
commit c38923b
Showing
4 changed files
with
109 additions
and
4 deletions.
There are no files selected for viewing
101 changes: 101 additions & 0 deletions
101
src/Qwack.Models/Models/AttributionSteps/ActivityStep.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Qwack.Core.Basic; | ||
using Qwack.Core.Cubes; | ||
using Qwack.Core.Instruments; | ||
using Qwack.Core.Models; | ||
using static Qwack.Core.Basic.Consts.Cubes; | ||
|
||
namespace Qwack.Models.Models.AttributionSteps; | ||
|
||
public class ActivityStep(Portfolio startPortfolio, Portfolio endPortfolio) : IPnLAttributionStep | ||
{ | ||
public (ICube endOfStepPvCube, IPvModel model) Attribute(IPvModel model, IPvModel endModel, ResultCube resultsCube, ICube lastPvCube, | ||
ICube riskCube, Currency reportingCcy) | ||
{ | ||
var (newTrades, removedTrades, ammendedTradesStart, ammendedTradesEnd) = startPortfolio.ActivityBooks(endPortfolio, endModel.VanillaModel.BuildDate); | ||
|
||
var pfEndDict = endPortfolio.Instruments.ToDictionary(x => x.TradeId, x => x.PortfolioName); | ||
var pfStartDict = startPortfolio.Instruments.ToDictionary(x => x.TradeId, x => x.PortfolioName); | ||
|
||
if (newTrades.Instruments.Count > 0) | ||
{ | ||
model = model.Rebuild(model.VanillaModel, newTrades); | ||
var newTradesPnL = model.PV(reportingCcy); | ||
var tidIx = newTradesPnL.GetColumnIndex(TradeId); | ||
var tTypeIx = newTradesPnL.GetColumnIndex(TradeType); | ||
foreach (var t in newTradesPnL.GetAllRows()) | ||
{ | ||
var tid = (string)t.MetaData[tidIx]; | ||
var row = new Dictionary<string, object> | ||
{ | ||
{ TradeId, tid}, | ||
{ TradeType, t.MetaData[tTypeIx] }, | ||
{ Step, "Activity" }, | ||
{ SubStep, "New" }, | ||
{ SubSubStep, string.Empty }, | ||
{ PointLabel, string.Empty }, | ||
{ "Portfolio", pfEndDict[tid]} | ||
}; | ||
resultsCube.AddRow(row, t.Value); | ||
} | ||
} | ||
|
||
if (removedTrades.Instruments.Count > 0) | ||
{ | ||
model = model.Rebuild(model.VanillaModel, removedTrades); | ||
var removedTradesPnL = model.PV(reportingCcy); | ||
|
||
var tidIx = removedTradesPnL.GetColumnIndex(TradeId); | ||
var tTypeIx = removedTradesPnL.GetColumnIndex(TradeType); | ||
|
||
foreach (var t in removedTradesPnL.GetAllRows()) | ||
{ | ||
var tid = (string)t.MetaData[tidIx]; | ||
var row = new Dictionary<string, object> | ||
{ | ||
{ TradeId, tid }, | ||
{ TradeType, t.MetaData[tTypeIx] }, | ||
{ Step, "Activity" }, | ||
{ SubStep, "Removed" }, | ||
{ SubSubStep, string.Empty }, | ||
{ PointLabel, string.Empty }, | ||
{ "Portfolio", pfStartDict[tid]} | ||
}; | ||
resultsCube.AddRow(row, -t.Value); | ||
} | ||
} | ||
|
||
if (ammendedTradesStart.Instruments.Count > 0) | ||
{ | ||
model = model.Rebuild(model.VanillaModel, ammendedTradesStart); | ||
var amendedTradesPnLStart = model.PV(reportingCcy); | ||
model = model.Rebuild(model.VanillaModel, ammendedTradesEnd); | ||
var amendedTradesPnLEnd = model.PV(reportingCcy); | ||
var amendedPnL = amendedTradesPnLEnd.QuickDifference(amendedTradesPnLStart); | ||
|
||
var tidIx = amendedTradesPnLStart.GetColumnIndex(TradeId); | ||
var tTypeIx = amendedTradesPnLStart.GetColumnIndex(TradeType); | ||
|
||
foreach (var t in amendedPnL.GetAllRows()) | ||
{ | ||
var tid = (string)t.MetaData[tidIx]; | ||
var row = new Dictionary<string, object> | ||
{ | ||
{ TradeId, tid }, | ||
{ TradeType, t.MetaData[tTypeIx] }, | ||
{ Step, "Activity" }, | ||
{ SubStep, "Ammended" }, | ||
{ SubSubStep, string.Empty }, | ||
{ PointLabel, string.Empty }, | ||
{ "Portfolio", pfStartDict[tid]} | ||
}; | ||
resultsCube.AddRow(row, t.Value); | ||
} | ||
} | ||
|
||
model = model.Rebuild(model.VanillaModel, endPortfolio); | ||
|
||
return (lastPvCube, model); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<VersionPrefix>0.8.51</VersionPrefix> | ||
<VersionPrefix>0.8.52</VersionPrefix> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.8.51 | ||
0.8.52 |