src/Bundles/Instruments/Base/Entity/Forward.php line 16

Open in your IDE?
  1. <?php
  2. namespace Bundles\Instruments\Base\Entity;
  3. use App\Entity\CurrencyPair;
  4. use App\Entity\Counterparty;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Bundles\Portfolios\Entity\Portfolio as Portfolio;
  8. use Bundles\Instruments\Base\Repository\ForwardRepository;
  9. use Bundles\Instruments\Base\Entity\CashFlows;
  10. use Doctrine\ORM\Mapping as ORM;
  11. /**
  12. * @ORM\Entity(repositoryClass=ForwardRepository::class)
  13. */
  14. class Forward {
  15. /**
  16. * @ORM\Id
  17. * @ORM\GeneratedValue
  18. * @ORM\Column(type="integer")
  19. */
  20. private $id;
  21. /**
  22. * @ORM\ManyToOne(targetEntity=Portfolio::class)
  23. * @ORM\JoinColumn(nullable=false)
  24. */
  25. private $Portfolio;
  26. /**
  27. * @ORM\ManyToOne(targetEntity=CurrencyPair::class)
  28. * @ORM\JoinColumn(nullable=false)
  29. */
  30. private $CurrencyPair;
  31. /**
  32. * @ORM\ManyToMany(targetEntity=CashFlows::class)
  33. * @ORM\JoinTable(name="forward_cash_flows")
  34. */
  35. private $committedCashflows;
  36. /**
  37. * @ORM\Column(type="string", length=10)
  38. */
  39. private $exposureDirection;
  40. /**
  41. * @ORM\Column(type="decimal", precision=20, scale=5)
  42. */
  43. private $amount;
  44. /**
  45. * @ORM\Column(type="decimal", precision=20, scale=5)
  46. */
  47. private $amountMinor;
  48. /**
  49. * @ORM\Column(type="decimal", precision=10, scale=4)
  50. */
  51. private $strike;
  52. /**
  53. * execution rate. Reikalingas counterparty limitui apskaiciuoti
  54. * @ORM\Column(type="decimal", precision=10, scale=4, nullable=true)
  55. */
  56. private $rate;
  57. /**
  58. * @ORM\Column(type="string", length=20)
  59. */
  60. private $dateExpire; //Execution date
  61. /**
  62. * @ORM\Column(type="string", length=20)
  63. */
  64. private $dateDelivery;
  65. /**
  66. * @ORM\Column(type="string", length=20, nullable=true)
  67. */
  68. private $dateOpen; //trade galima drawdown, kai trade $dateOpen <= now
  69. /**
  70. * trado kurimo metu, uzsisaugojam, koks tuo metu buvo hedging policy taikytas
  71. * pagal spot ir dienu kiekis nuo execution date iki sukurimo dienos
  72. * pagal si parametra summary isvedamas koks siulomas Hedging policy
  73. * @ORM\Column(type="decimal", precision=5, scale=2, nullable=true)
  74. */
  75. private $policyRatio;
  76. /**
  77. * @ORM\Column(type="boolean", nullable=true)
  78. */
  79. private $status;
  80. /**
  81. * @ORM\ManyToOne(targetEntity=Counterparty::class, inversedBy="trades")
  82. */
  83. private $Counterparty;
  84. /**
  85. * @ORM\Column(type="boolean", nullable=true)
  86. */
  87. private $usedRemoteSystem = false;
  88. /**
  89. * @ORM\Column(type="text", nullable=true)
  90. */
  91. private $comment;
  92. /**
  93. * trade gali buti siu tipu: forward(default), spot, option
  94. * @ORM\Column(type="text", nullable=true)
  95. */
  96. private $type = 'forward';
  97. /**
  98. * @ORM\Column(type="text", nullable=true)
  99. */
  100. private $tradeNumber;
  101. /**
  102. * @ORM\Column(type="text", nullable=true)
  103. */
  104. private $brokerTradeData;
  105. /**
  106. * @ORM\OneToMany(targetEntity=ForwardOperations::class, mappedBy="Trade", orphanRemoval=true)
  107. */
  108. private $ForwardOperations;
  109. /**
  110. * @ORM\Column(type="integer", nullable=true)
  111. */
  112. private $parentId;
  113. private $lastAction;
  114. private $actionAmount;
  115. private $opositeAmount;
  116. private $opositeCurrency;
  117. /**
  118. * @ORM\Column(type="integer", nullable=true)
  119. */
  120. private $valuation;
  121. /**
  122. * @ORM\Column(type="integer", nullable=true)
  123. */
  124. private $optionId;
  125. /**
  126. * @ORM\Column(type="json", nullable=true)
  127. */
  128. private $optionParams;
  129. private $valuationByBudgetRate;
  130. public function __construct() {
  131. $this->ForwardOperations = new ArrayCollection();
  132. $this->committedCashflows = new ArrayCollection();
  133. }
  134. public function getId(): ?int {
  135. return $this->id;
  136. }
  137. public function setId(?int $id): self {
  138. $this->id = $id;
  139. return $this;
  140. }
  141. public function getPortfolio(): ?Portfolio {
  142. return $this->Portfolio;
  143. }
  144. public function setPortfolio(?Portfolio $Portfolio): self {
  145. $this->Portfolio = $Portfolio;
  146. return $this;
  147. }
  148. public function getCurrencyPair(): ?CurrencyPair {
  149. return $this->CurrencyPair;
  150. }
  151. public function setCurrencyPair(?CurrencyPair $CurrencyPair): self {
  152. $this->CurrencyPair = $CurrencyPair;
  153. return $this;
  154. }
  155. public function getExposureDirection(): ?string {
  156. return $this->exposureDirection;
  157. }
  158. public function setExposureDirection(string $exposureDirection): self {
  159. $this->exposureDirection = $exposureDirection;
  160. return $this;
  161. }
  162. public function getAmount(): ?string {
  163. return round($this->amount, 2);
  164. }
  165. public function setAmount($amount): self {
  166. $this->amount = $amount;
  167. return $this;
  168. }
  169. /**
  170. * @return mixed
  171. */
  172. public function getAmountMinor() {
  173. if (!empty($this->amountMinor)) {
  174. return $this->amountMinor;
  175. }
  176. return $this->amount * $this->strike;
  177. }
  178. /**
  179. * @param mixed $amountMinor
  180. */
  181. public function setAmountMinor($amountMinor): void {
  182. $this->amountMinor = $amountMinor;
  183. }
  184. public function getStrike(): ?string {
  185. return round($this->strike, 5);
  186. }
  187. public function setStrike($strike): self {
  188. $this->strike = $strike;
  189. return $this;
  190. }
  191. public function getDateExpire(): ?string {
  192. return $this->dateExpire;
  193. }
  194. public function setDateExpire($dateExpire): self {
  195. $this->dateExpire = $dateExpire;
  196. return $this;
  197. }
  198. public function getDateDelivery(): ?string {
  199. return $this->dateDelivery;
  200. }
  201. public function setDateDelivery($dateDelivery): self {
  202. $this->dateDelivery = $dateDelivery;
  203. return $this;
  204. }
  205. public function getStatus(): ?bool {
  206. return $this->status;
  207. }
  208. public function setStatus(?bool $status): self {
  209. $this->status = $status;
  210. return $this;
  211. }
  212. public function getCounterparty(): ?Counterparty {
  213. return $this->Counterparty;
  214. }
  215. public function setCounterparty(?Counterparty $Counterparty): self {
  216. $this->Counterparty = $Counterparty;
  217. return $this;
  218. }
  219. public function getComment(): ?string {
  220. return $this->comment;
  221. }
  222. public function setComment(?string $comment): self {
  223. $this->comment = $comment;
  224. return $this;
  225. }
  226. public function __toString() {
  227. return ''.$this->getId();
  228. }
  229. /**
  230. * @return mixed
  231. */
  232. public function getTradeNumber() {
  233. return $this->tradeNumber;
  234. }
  235. /**
  236. * @param mixed $tradeNumber
  237. */
  238. public function setTradeNumber($tradeNumber): void {
  239. $this->tradeNumber = $tradeNumber;
  240. }
  241. /**
  242. * @return Collection<int, ForwardOperations>
  243. */
  244. public function getForwardOperations(): Collection {
  245. return $this->ForwardOperations;
  246. }
  247. public function addTradeOperation(ForwardOperations $analyticsTradesOperation): self {
  248. if (!$this->ForwardOperations->contains($analyticsTradesOperation)) {
  249. $this->ForwardOperations[] = $analyticsTradesOperation;
  250. $analyticsTradesOperation->setTrade($this);
  251. }
  252. return $this;
  253. }
  254. public function removeAnalyticsTradesOperation(ForwardOperations $forwardOperation): self {
  255. if ($this->ForwardOperations->removeElement($forwardOperation)) {
  256. // set the owning side to null (unless already changed)
  257. if ($forwardOperation->getTrade() === $this) {
  258. $forwardOperation->setTrade(null);
  259. }
  260. }
  261. return $this;
  262. }
  263. /**
  264. * @return mixed
  265. */
  266. public function getLastAction() {
  267. return $this->lastAction;
  268. }
  269. /**
  270. * @param mixed $lastAction
  271. */
  272. public function setLastAction($lastAction): void {
  273. $this->lastAction = $lastAction;
  274. }
  275. /**
  276. * @return mixed
  277. */
  278. public function getParentId() {
  279. return $this->parentId;
  280. }
  281. /**
  282. * @param mixed $parentId
  283. */
  284. public function setParentId($parentId): void {
  285. $this->parentId = $parentId;
  286. }
  287. /**
  288. * @return Collection<int, CashFlows>
  289. */
  290. public function getCommittedCashflows(): Collection {
  291. return $this->committedCashflows;
  292. }
  293. public function addCommittedCashflows(CashFlows $committedCashflow): self {
  294. if (!$this->committedCashflows->contains($committedCashflow)) {
  295. $this->committedCashflows[] = $committedCashflow;
  296. }
  297. return $this;
  298. }
  299. public function removeCommittedCashflows(CashFlows $committedCashflow): self {
  300. $this->committedCashflows->removeElement($committedCashflow);
  301. return $this;
  302. }
  303. /**
  304. * @return Collection<int, CashFlows>
  305. */
  306. public function resetCommittedCashflows() {
  307. $this->committedCashflows = new ArrayCollection();
  308. }
  309. /**
  310. * @return mixed
  311. */
  312. public function getRate() {
  313. return $this->rate;
  314. }
  315. /**
  316. * @param mixed $rate
  317. */
  318. public function setRate($rate): void {
  319. $this->rate = $rate;
  320. }
  321. public function getCurrency() {
  322. if ($this->getExposureDirection() == 'receive') {
  323. $this->opositeCurrency = $this->getCurrencyPair()->getCurrencyNameByNumber(1);
  324. return $this->getCurrencyPair()->getCurrencyNameByNumber(2);
  325. }
  326. $this->opositeCurrency = $this->getCurrencyPair()->getCurrencyNameByNumber(2);
  327. return $this->getCurrencyPair()->getCurrencyNameByNumber(1);
  328. }
  329. public function getActionAmount() {
  330. $this->actionAmount = $this->getAmount();
  331. if ($this->getExposureDirection() == 'receive') {
  332. $this->actionAmount = $this->getAmountMinor();
  333. }
  334. return $this->actionAmount;
  335. }
  336. public function getOpositeAmount() {
  337. $this->opositeAmount = $this->getAmountMinor();
  338. if ($this->getExposureDirection() == 'receive') {
  339. $this->opositeAmount = $this->getAmount();
  340. }
  341. return $this->opositeAmount;
  342. }
  343. public function getOpositeCurrency() {
  344. if (empty($this->opositeCurrency)) {
  345. $this->opositeCurrency = $this->getCurrencyPair()->getCurrencyNameByNumber(1);
  346. if ($this->getExposureDirection() == 'receive') {
  347. $this->opositeCurrency = $this->getCurrencyPair()->getCurrencyNameByNumber(2);
  348. }
  349. }
  350. return $this->opositeCurrency;
  351. }
  352. public function setValuation($valuation) {
  353. $this->valuation = $valuation;
  354. }
  355. public function getValuation() {
  356. return $this->valuation;
  357. }
  358. /**
  359. * @return mixed
  360. */
  361. public function getOptionId() {
  362. return $this->optionId;
  363. }
  364. /**
  365. * @param mixed $optionId
  366. */
  367. public function setOptionId($optionId): void {
  368. $this->optionId = $optionId;
  369. }
  370. /**
  371. * @return mixed
  372. */
  373. public function getOptionParams() {
  374. return $this->optionParams;
  375. }
  376. /**
  377. * @param mixed $optionParams
  378. */
  379. public function setOptionParams($optionParams): void {
  380. $this->optionParams = $optionParams;
  381. }
  382. /**
  383. * @return mixed
  384. */
  385. public function getPolicyRatio() {
  386. return $this->policyRatio;
  387. }
  388. /**
  389. * @param mixed $policyRatio
  390. */
  391. public function setPolicyRatio($policyRatio): void {
  392. $this->policyRatio = $policyRatio;
  393. }
  394. /**
  395. * @return mixed
  396. */
  397. public function getType() {
  398. return $this->type;
  399. }
  400. /**
  401. * @param mixed $type
  402. */
  403. public function setType($type): void {
  404. $this->type = $type;
  405. }
  406. /**
  407. * @return mixed
  408. */
  409. public function getValuationByBudgetRate() {
  410. return $this->valuationByBudgetRate;
  411. }
  412. public function setValuationByBudgetRate($valuation) {
  413. $this->valuationByBudgetRate = $valuation;
  414. }
  415. public function isUsedRemoteSystem(): ?bool {
  416. return $this->usedRemoteSystem;
  417. }
  418. public function setUsedRemoteSystem(?bool $usedRemoteSystem): void {
  419. $this->usedRemoteSystem = $usedRemoteSystem;
  420. }
  421. public function getBrokerTradeData() {
  422. if (empty($this->brokerTradeData)) {
  423. return null;
  424. }
  425. return json_decode($this->brokerTradeData, true);
  426. }
  427. public function setBrokerTradeData($brokerTradeData): void {
  428. $this->brokerTradeData = $brokerTradeData;
  429. }
  430. public function getDateOpen() {
  431. return $this->dateOpen;
  432. }
  433. public function setDateOpen($dateOpen) {
  434. $this->dateOpen = $dateOpen;
  435. }
  436. }