<?php
namespace Bundles\Instruments\Base\Entity;
use App\Entity\CurrencyPair;
use App\Entity\Counterparty;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Bundles\Portfolios\Entity\Portfolio as Portfolio;
use Bundles\Instruments\Base\Repository\ForwardRepository;
use Bundles\Instruments\Base\Entity\CashFlows;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=ForwardRepository::class)
*/
class Forward {
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=Portfolio::class)
* @ORM\JoinColumn(nullable=false)
*/
private $Portfolio;
/**
* @ORM\ManyToOne(targetEntity=CurrencyPair::class)
* @ORM\JoinColumn(nullable=false)
*/
private $CurrencyPair;
/**
* @ORM\ManyToMany(targetEntity=CashFlows::class)
* @ORM\JoinTable(name="forward_cash_flows")
*/
private $committedCashflows;
/**
* @ORM\Column(type="string", length=10)
*/
private $exposureDirection;
/**
* @ORM\Column(type="decimal", precision=20, scale=5)
*/
private $amount;
/**
* @ORM\Column(type="decimal", precision=20, scale=5)
*/
private $amountMinor;
/**
* @ORM\Column(type="decimal", precision=10, scale=4)
*/
private $strike;
/**
* execution rate. Reikalingas counterparty limitui apskaiciuoti
* @ORM\Column(type="decimal", precision=10, scale=4, nullable=true)
*/
private $rate;
/**
* @ORM\Column(type="string", length=20)
*/
private $dateExpire; //Execution date
/**
* @ORM\Column(type="string", length=20)
*/
private $dateDelivery;
/**
* @ORM\Column(type="string", length=20, nullable=true)
*/
private $dateOpen; //trade galima drawdown, kai trade $dateOpen <= now
/**
* trado kurimo metu, uzsisaugojam, koks tuo metu buvo hedging policy taikytas
* pagal spot ir dienu kiekis nuo execution date iki sukurimo dienos
* pagal si parametra summary isvedamas koks siulomas Hedging policy
* @ORM\Column(type="decimal", precision=5, scale=2, nullable=true)
*/
private $policyRatio;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $status;
/**
* @ORM\ManyToOne(targetEntity=Counterparty::class, inversedBy="trades")
*/
private $Counterparty;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $usedRemoteSystem = false;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $comment;
/**
* trade gali buti siu tipu: forward(default), spot, option
* @ORM\Column(type="text", nullable=true)
*/
private $type = 'forward';
/**
* @ORM\Column(type="text", nullable=true)
*/
private $tradeNumber;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $brokerTradeData;
/**
* @ORM\OneToMany(targetEntity=ForwardOperations::class, mappedBy="Trade", orphanRemoval=true)
*/
private $ForwardOperations;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $parentId;
private $lastAction;
private $actionAmount;
private $opositeAmount;
private $opositeCurrency;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $valuation;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $optionId;
/**
* @ORM\Column(type="json", nullable=true)
*/
private $optionParams;
private $valuationByBudgetRate;
public function __construct() {
$this->ForwardOperations = new ArrayCollection();
$this->committedCashflows = new ArrayCollection();
}
public function getId(): ?int {
return $this->id;
}
public function setId(?int $id): self {
$this->id = $id;
return $this;
}
public function getPortfolio(): ?Portfolio {
return $this->Portfolio;
}
public function setPortfolio(?Portfolio $Portfolio): self {
$this->Portfolio = $Portfolio;
return $this;
}
public function getCurrencyPair(): ?CurrencyPair {
return $this->CurrencyPair;
}
public function setCurrencyPair(?CurrencyPair $CurrencyPair): self {
$this->CurrencyPair = $CurrencyPair;
return $this;
}
public function getExposureDirection(): ?string {
return $this->exposureDirection;
}
public function setExposureDirection(string $exposureDirection): self {
$this->exposureDirection = $exposureDirection;
return $this;
}
public function getAmount(): ?string {
return round($this->amount, 2);
}
public function setAmount($amount): self {
$this->amount = $amount;
return $this;
}
/**
* @return mixed
*/
public function getAmountMinor() {
if (!empty($this->amountMinor)) {
return $this->amountMinor;
}
return $this->amount * $this->strike;
}
/**
* @param mixed $amountMinor
*/
public function setAmountMinor($amountMinor): void {
$this->amountMinor = $amountMinor;
}
public function getStrike(): ?string {
return round($this->strike, 5);
}
public function setStrike($strike): self {
$this->strike = $strike;
return $this;
}
public function getDateExpire(): ?string {
return $this->dateExpire;
}
public function setDateExpire($dateExpire): self {
$this->dateExpire = $dateExpire;
return $this;
}
public function getDateDelivery(): ?string {
return $this->dateDelivery;
}
public function setDateDelivery($dateDelivery): self {
$this->dateDelivery = $dateDelivery;
return $this;
}
public function getStatus(): ?bool {
return $this->status;
}
public function setStatus(?bool $status): self {
$this->status = $status;
return $this;
}
public function getCounterparty(): ?Counterparty {
return $this->Counterparty;
}
public function setCounterparty(?Counterparty $Counterparty): self {
$this->Counterparty = $Counterparty;
return $this;
}
public function getComment(): ?string {
return $this->comment;
}
public function setComment(?string $comment): self {
$this->comment = $comment;
return $this;
}
public function __toString() {
return ''.$this->getId();
}
/**
* @return mixed
*/
public function getTradeNumber() {
return $this->tradeNumber;
}
/**
* @param mixed $tradeNumber
*/
public function setTradeNumber($tradeNumber): void {
$this->tradeNumber = $tradeNumber;
}
/**
* @return Collection<int, ForwardOperations>
*/
public function getForwardOperations(): Collection {
return $this->ForwardOperations;
}
public function addTradeOperation(ForwardOperations $analyticsTradesOperation): self {
if (!$this->ForwardOperations->contains($analyticsTradesOperation)) {
$this->ForwardOperations[] = $analyticsTradesOperation;
$analyticsTradesOperation->setTrade($this);
}
return $this;
}
public function removeAnalyticsTradesOperation(ForwardOperations $forwardOperation): self {
if ($this->ForwardOperations->removeElement($forwardOperation)) {
// set the owning side to null (unless already changed)
if ($forwardOperation->getTrade() === $this) {
$forwardOperation->setTrade(null);
}
}
return $this;
}
/**
* @return mixed
*/
public function getLastAction() {
return $this->lastAction;
}
/**
* @param mixed $lastAction
*/
public function setLastAction($lastAction): void {
$this->lastAction = $lastAction;
}
/**
* @return mixed
*/
public function getParentId() {
return $this->parentId;
}
/**
* @param mixed $parentId
*/
public function setParentId($parentId): void {
$this->parentId = $parentId;
}
/**
* @return Collection<int, CashFlows>
*/
public function getCommittedCashflows(): Collection {
return $this->committedCashflows;
}
public function addCommittedCashflows(CashFlows $committedCashflow): self {
if (!$this->committedCashflows->contains($committedCashflow)) {
$this->committedCashflows[] = $committedCashflow;
}
return $this;
}
public function removeCommittedCashflows(CashFlows $committedCashflow): self {
$this->committedCashflows->removeElement($committedCashflow);
return $this;
}
/**
* @return Collection<int, CashFlows>
*/
public function resetCommittedCashflows() {
$this->committedCashflows = new ArrayCollection();
}
/**
* @return mixed
*/
public function getRate() {
return $this->rate;
}
/**
* @param mixed $rate
*/
public function setRate($rate): void {
$this->rate = $rate;
}
public function getCurrency() {
if ($this->getExposureDirection() == 'receive') {
$this->opositeCurrency = $this->getCurrencyPair()->getCurrencyNameByNumber(1);
return $this->getCurrencyPair()->getCurrencyNameByNumber(2);
}
$this->opositeCurrency = $this->getCurrencyPair()->getCurrencyNameByNumber(2);
return $this->getCurrencyPair()->getCurrencyNameByNumber(1);
}
public function getActionAmount() {
$this->actionAmount = $this->getAmount();
if ($this->getExposureDirection() == 'receive') {
$this->actionAmount = $this->getAmountMinor();
}
return $this->actionAmount;
}
public function getOpositeAmount() {
$this->opositeAmount = $this->getAmountMinor();
if ($this->getExposureDirection() == 'receive') {
$this->opositeAmount = $this->getAmount();
}
return $this->opositeAmount;
}
public function getOpositeCurrency() {
if (empty($this->opositeCurrency)) {
$this->opositeCurrency = $this->getCurrencyPair()->getCurrencyNameByNumber(1);
if ($this->getExposureDirection() == 'receive') {
$this->opositeCurrency = $this->getCurrencyPair()->getCurrencyNameByNumber(2);
}
}
return $this->opositeCurrency;
}
public function setValuation($valuation) {
$this->valuation = $valuation;
}
public function getValuation() {
return $this->valuation;
}
/**
* @return mixed
*/
public function getOptionId() {
return $this->optionId;
}
/**
* @param mixed $optionId
*/
public function setOptionId($optionId): void {
$this->optionId = $optionId;
}
/**
* @return mixed
*/
public function getOptionParams() {
return $this->optionParams;
}
/**
* @param mixed $optionParams
*/
public function setOptionParams($optionParams): void {
$this->optionParams = $optionParams;
}
/**
* @return mixed
*/
public function getPolicyRatio() {
return $this->policyRatio;
}
/**
* @param mixed $policyRatio
*/
public function setPolicyRatio($policyRatio): void {
$this->policyRatio = $policyRatio;
}
/**
* @return mixed
*/
public function getType() {
return $this->type;
}
/**
* @param mixed $type
*/
public function setType($type): void {
$this->type = $type;
}
/**
* @return mixed
*/
public function getValuationByBudgetRate() {
return $this->valuationByBudgetRate;
}
public function setValuationByBudgetRate($valuation) {
$this->valuationByBudgetRate = $valuation;
}
public function isUsedRemoteSystem(): ?bool {
return $this->usedRemoteSystem;
}
public function setUsedRemoteSystem(?bool $usedRemoteSystem): void {
$this->usedRemoteSystem = $usedRemoteSystem;
}
public function getBrokerTradeData() {
if (empty($this->brokerTradeData)) {
return null;
}
return json_decode($this->brokerTradeData, true);
}
public function setBrokerTradeData($brokerTradeData): void {
$this->brokerTradeData = $brokerTradeData;
}
public function getDateOpen() {
return $this->dateOpen;
}
public function setDateOpen($dateOpen) {
$this->dateOpen = $dateOpen;
}
}