diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 9e30c2a..ac4f2dd 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -4,12 +4,15 @@ import { CashFlowComponent } from './cash-flow/cash-flow.component'; import { FutureValueComponent } from './future-value/future-value.component'; import { PresentValueComponent } from './present-value/present-value.component' import { DoubleComponent } from './double/double.component'; +import { GainLossComponent } from './gain-loss/gain-loss.component'; + const routes: Routes = [ { path: 'cash-flow', component: CashFlowComponent }, { path: 'future-value-of-money', component: FutureValueComponent }, { path: 'present-value-of-money', component: PresentValueComponent }, - { path: 'time-to-double-investment', component: DoubleComponent } + { path: 'time-to-double-investment', component: DoubleComponent }, + { path: 'percent-gain-or-loss', component: GainLossComponent } ]; @NgModule({ diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 6ca4e47..f2aef03 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -8,6 +8,7 @@ import { CashFlowComponent } from './cash-flow/cash-flow.component'; import { FutureValueComponent } from './future-value/future-value.component'; import { PresentValueComponent } from './present-value/present-value.component'; import { DoubleComponent } from './double/double.component'; +import { GainLossComponent } from './gain-loss/gain-loss.component'; @NgModule({ declarations: [ @@ -15,7 +16,8 @@ import { DoubleComponent } from './double/double.component'; CashFlowComponent, FutureValueComponent, PresentValueComponent, - DoubleComponent + DoubleComponent, + GainLossComponent ], imports: [ BrowserModule, diff --git a/src/app/gain-loss.ts b/src/app/gain-loss.ts new file mode 100644 index 0000000..ba87b7e --- /dev/null +++ b/src/app/gain-loss.ts @@ -0,0 +1,7 @@ +export class GainLoss { + market: number; + purchase: number; + difference: number; + percent: number; + growth: string; +} \ No newline at end of file diff --git a/src/app/gain-loss/gain-loss.component.html b/src/app/gain-loss/gain-loss.component.html new file mode 100644 index 0000000..b759732 --- /dev/null +++ b/src/app/gain-loss/gain-loss.component.html @@ -0,0 +1,26 @@ +

Percent Gain or Loss on Investment

+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+

Yield

+

{{ GainLoss.percent }}% {{ GainLoss.growth }}

+
+
+

+ By entering a purchase price and the current value of an asset you can calculate what percent you have gained or lost on an particular asset. +

+
+
\ No newline at end of file diff --git a/src/app/gain-loss/gain-loss.component.scss b/src/app/gain-loss/gain-loss.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/gain-loss/gain-loss.component.spec.ts b/src/app/gain-loss/gain-loss.component.spec.ts new file mode 100644 index 0000000..a583f3a --- /dev/null +++ b/src/app/gain-loss/gain-loss.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { GainLossComponent } from './gain-loss.component'; + +describe('GainLossComponent', () => { + let component: GainLossComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ GainLossComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(GainLossComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/gain-loss/gain-loss.component.ts b/src/app/gain-loss/gain-loss.component.ts new file mode 100644 index 0000000..fd88eeb --- /dev/null +++ b/src/app/gain-loss/gain-loss.component.ts @@ -0,0 +1,37 @@ +import { Component, OnInit } from '@angular/core'; +import { GainLoss } from '../gain-loss' + +@Component({ + selector: 'app-gain-loss', + templateUrl: './gain-loss.component.html', + styleUrls: ['./gain-loss.component.scss'] +}) +export class GainLossComponent implements OnInit { + + GainLoss: GainLoss = { + market: 0, + purchase: 0, + difference: 0, + percent: 0, + growth: '' + } + + calculatePercent() { + this.GainLoss.difference = this.GainLoss.market - this.GainLoss.purchase; + + if (this.GainLoss.difference < 0) { + this.GainLoss.growth = 'loss'; + } else { + this.GainLoss.growth = 'gain'; + } + + this.GainLoss.percent = Number(((this.GainLoss.difference / this.GainLoss.purchase) * 100).toFixed(2)) < 0 ? -Number(((this.GainLoss.difference / this.GainLoss.purchase) * 100).toFixed(2)) : Number(((this.GainLoss.difference / this.GainLoss.purchase) * 100).toFixed(2)) ; + + } + + constructor() { } + + ngOnInit() { + } + +}