|
| 1 | +import { |
| 2 | + Entity, |
| 3 | + PrimaryGeneratedColumn, |
| 4 | + Column, |
| 5 | + ManyToOne, |
| 6 | + JoinColumn, |
| 7 | + Index, |
| 8 | + CreateDateColumn, |
| 9 | + UpdateDateColumn, |
| 10 | +} from 'typeorm'; |
| 11 | +import { VirtualAsset } from '../../database/entities/virtual-asset.entity'; |
| 12 | +import { OptionType } from '../enums/option-type.enum'; |
| 13 | +import { OptionStatus } from '../enums/option-status.enum'; |
| 14 | +import { ExerciseStyle } from '../enums/exercise-style.enum'; |
| 15 | + |
| 16 | +@Entity('option_contracts') |
| 17 | +@Index(['underlyingAssetId', 'expirationDate']) |
| 18 | +@Index(['status', 'expirationDate']) |
| 19 | +export class OptionContract { |
| 20 | + @PrimaryGeneratedColumn() |
| 21 | + id: number; |
| 22 | + |
| 23 | + @Column({ type: 'varchar' }) |
| 24 | + optionType: OptionType; |
| 25 | + |
| 26 | + @Column({ type: 'varchar', default: ExerciseStyle.EUROPEAN }) |
| 27 | + exerciseStyle: ExerciseStyle; |
| 28 | + |
| 29 | + @Column() |
| 30 | + @Index() |
| 31 | + underlyingAssetId: number; |
| 32 | + |
| 33 | + @ManyToOne(() => VirtualAsset) |
| 34 | + @JoinColumn({ name: 'underlyingAssetId' }) |
| 35 | + underlyingAsset: VirtualAsset; |
| 36 | + |
| 37 | + /** Strike price in quote asset units. */ |
| 38 | + @Column('decimal', { precision: 18, scale: 8 }) |
| 39 | + strikePrice: number; |
| 40 | + |
| 41 | + @Column({ type: 'datetime' }) |
| 42 | + expirationDate: Date; |
| 43 | + |
| 44 | + /** Contract size = number of underlying units per contract. */ |
| 45 | + @Column('decimal', { precision: 18, scale: 8, default: 1 }) |
| 46 | + contractSize: number; |
| 47 | + |
| 48 | + /** Current market price of the underlying at creation. */ |
| 49 | + @Column('decimal', { precision: 18, scale: 8 }) |
| 50 | + underlyingPriceAtCreation: number; |
| 51 | + |
| 52 | + /** Option premium per unit. */ |
| 53 | + @Column('decimal', { precision: 18, scale: 8 }) |
| 54 | + premium: number; |
| 55 | + |
| 56 | + /** Implied volatility used for pricing (annualized). */ |
| 57 | + @Column('decimal', { precision: 10, scale: 8, default: 0.3 }) |
| 58 | + impliedVolatility: number; |
| 59 | + |
| 60 | + /** Risk-free interest rate used for pricing. */ |
| 61 | + @Column('decimal', { precision: 10, scale: 8, default: 0.05 }) |
| 62 | + riskFreeRate: number; |
| 63 | + |
| 64 | + /** Delta — option sensitivity to underlying price. */ |
| 65 | + @Column('decimal', { precision: 10, scale: 8, default: 0 }) |
| 66 | + delta: number; |
| 67 | + |
| 68 | + /** Gamma — rate of change of delta. */ |
| 69 | + @Column('decimal', { precision: 10, scale: 8, default: 0 }) |
| 70 | + gamma: number; |
| 71 | + |
| 72 | + /** Vega — sensitivity to volatility changes. */ |
| 73 | + @Column('decimal', { precision: 10, scale: 8, default: 0 }) |
| 74 | + vega: number; |
| 75 | + |
| 76 | + /** Theta — time decay. */ |
| 77 | + @Column('decimal', { precision: 10, scale: 8, default: 0 }) |
| 78 | + theta: number; |
| 79 | + |
| 80 | + /** Rho — sensitivity to interest rate changes. */ |
| 81 | + @Column('decimal', { precision: 10, scale: 8, default: 0 }) |
| 82 | + rho: number; |
| 83 | + |
| 84 | + /** Total contracts available (initial supply). */ |
| 85 | + @Column('decimal', { precision: 18, scale: 8, default: 0 }) |
| 86 | + totalSupply: number; |
| 87 | + |
| 88 | + /** Contracts still outstanding (unsold + unexercised). */ |
| 89 | + @Column('decimal', { precision: 18, scale: 8, default: 0 }) |
| 90 | + openInterest: number; |
| 91 | + |
| 92 | + /** Whether option was in-the-money at last check. */ |
| 93 | + @Column({ default: false }) |
| 94 | + inTheMoney: boolean; |
| 95 | + |
| 96 | + @Column({ type: 'varchar', default: OptionStatus.ACTIVE }) |
| 97 | + status: OptionStatus; |
| 98 | + |
| 99 | + @CreateDateColumn() |
| 100 | + createdAt: Date; |
| 101 | + |
| 102 | + @UpdateDateColumn() |
| 103 | + updatedAt: Date; |
| 104 | +} |
0 commit comments