Public Function CalcEffectOfTransactionOnMargin(targdate As Date) As Decimal 'new ' The code for this function is provided to you in a link from the homework. ' Make sure that you understand the financial logic. ' This function calculates the effect of the current transaction on your overall margin Select Case type Case "Sell" ' Sell has no effect on margin because you can only sell what you have long Return 0 ' effect of transaction on margin Case "Buy" If currentPositionInAP >= 0 Then Return 0 Else If qty >= Math.Abs(currentPositionInAP) Then Return -currentPositionInAP * mtm ' buying eliminates all margin for this symbol Else Return (qty * mtm) ' buying reduces the margin End If End If Case "SellShort" Return -qty * mtm ' Selling short is easy: it always increases the margin Case "CashDiv" Return 0 Case "X-Call" ' Two effects on margin: the change in options and the change in stocks Dim OptionEffect As Decimal = 0 underlierCurrentPositionInAP = GetCurrentPositionInAP(underlier) ' first the effect of exercising the call on the call position If currentPositionInAP < 0 Then OptionEffect = qty * mtm ' i.e., it reduces the margin Else OptionEffect = 0 End If ' next, the effect of the called stock ' two cases: long and short calls. If currentPositionInAP >= 0 Then ' long call is like buying If underlierCurrentPositionInAP >= 0 Then Return OptionEffect Else If qty >= Math.Abs(underlierCurrentPositionInAP) Then Return OptionEffect - (underlierCurrentPositionInAP * mtmUnderlier) ' X-call eliminates all margin for this symbol Else Return OptionEffect + (qty * mtmUnderlier) ' X-call reduces the margin End If End If Else ' exercising short calls is like selling If underlierCurrentPositionInAP <= 0 Then Return OptionEffect - (qty * mtmUnderlier) Else ' underlier positive If underlierCurrentPositionInAP >= qty Then Return OptionEffect Else Return OptionEffect - ((qty - underlierCurrentPositionInAP) * (qty * mtmUnderlier)) End If End If End If Case "X-Put" ' Two effects on margin: the change in options and the change in stocks Dim OptionEffect As Decimal = 0 underlierCurrentPositionInAP = GetCurrentPositionInAP(underlier) ' first the effect of exercising the option on the put position If currentPositionInAP < 0 Then OptionEffect = qty * mtm ' and it reduces the margin Else OptionEffect = 0 End If ' next, the effect of the stock ' two cases: long and short puts If currentPositionInAP < 0 Then ' short put is like buying If underlierCurrentPositionInAP >= 0 Then Return OptionEffect Else If qty >= Math.Abs(underlierCurrentPositionInAP) Then Return OptionEffect - (underlierCurrentPositionInAP * mtmUnderlier) ' X-put eliminates all margin for this symbol Else Return OptionEffect + (qty * mtmUnderlier) ' X-put reduces the margin End If End If Else ' long put is like selling If underlierCurrentPositionInAP <= 0 Then Return OptionEffect - (qty * mtmUnderlier) Else ' underlier positive If underlierCurrentPositionInAP >= qty Then Return OptionEffect Else Return OptionEffect - ((qty - underlierCurrentPositionInAP) * mtmUnderlier) End If End If End If End Select MessageBox.Show("Holy BatApples! I could not figure out the impact of " + symbol + " on margin. I returned $0.") Return 0 End Function