diagonals working except for start/end times

This commit is contained in:
Tim
2024-05-07 15:02:54 -04:00
parent c3c5db9c23
commit a68c4a4b05
5 changed files with 42 additions and 44 deletions

View File

@@ -19,7 +19,7 @@
label="Price"
/>
</td>
<td rowspan="2" class="weight">{{ allocationTexts[weights.length-1] }}</td>
<td rowspan="2" class="weight" style="vertical-align: bottom">{{ allocationTexts[weights.length-1] }}</td>
</tr>
<tr>
<td>
@@ -36,7 +36,7 @@
</tr>
<tr v-for="i in innerIndexes" class="ml-5">
<td class="text-right">&nbsp;</td>
<td colspan="2" class="text-center"><i>Diagonal</i></td>
<td colspan="2" class="text-center">&mdash; Interior Line &mdash;</td>
<td class="weight">{{ allocationTexts[i] }}</td>
</tr>
<tr v-if="weights.length>1">
@@ -52,7 +52,7 @@
label="Price"
/>
</td>
<td rowspan="2" class="weight">{{ allocationTexts[0] }}</td>
<td rowspan="2" class="weight" style="vertical-align: top">{{ allocationTexts[0] }}</td>
</tr>
<tr v-if="weights.length>1">
<td>
@@ -109,18 +109,17 @@ builderDefaults(props.builder, {
function buildTranches() {
throw Error('unimplemented') // todo
const order = props.order
const builder = props.builder
const tranches = []
console.log('buildTranches', builder, order, tranches)
const la = buildLine(_endpoints[0])
const lb = buildLine(_endpoints[1])
console.log('buildTranches', builder, order, _endpoints.value)
const la = _endpoints.value[0] // use the flatline format which is a vector of length 4, useful for vectorInterpolate()
const lb = _endpoints.value[1]
const ws = weights.value
for (let i = 0; i < ws.length; i++) {
const w = ws[i]
const line = vectorInterpolate(la, lb, i/(ws.length-1))
const line = ws.length === 1 ? la : vectorInterpolate(la, lb, i/(ws.length-1))
const t = newTranche({fraction: w * MAX_FRACTION})
const symbol = co.selectedSymbol
console.log('symbol', symbol)
@@ -137,7 +136,7 @@ function flattenLine(l) {
function buildLine(f) {
console.log('buildLine', f)
// console.log('buildLine', f)
return f === null ? null : [{time: f[0], price: f[1]}, {time: f[2], price: f[3]}]
}
@@ -243,17 +242,13 @@ const price2B = computed({
})
function update(a, b) { // a and b are lines of two points
console.log('update', a, b)
if (!vectorEquals(props.builder.lineA, a) || !vectorEquals(props.builder.lineB, b)) {
console.log('update was dirty')
_endpoints.value = [flattenLine(a), flattenLine(b)]
const newBuilder = {...props.builder}
newBuilder.lineA = a
newBuilder.lineB = b
emit('update:builder', newBuilder)
}
else
console.log('update was not dirty')
}
@@ -290,14 +285,14 @@ function getModelValue(model) {
if (!model.pointA || !model.pointB)
return null
const result = flattenLine([model.pointA, model.pointB]);
console.log('getModelValue', {...model}, result)
// console.log('getModelValue', {...model}, result)
return result // this is the vector the RungBuilder will interpolate
}
function setModelValue(model, value) {
const oldModel = {...model};
console.log('setModelValue', oldModel, value)
// console.log('setModelValue', oldModel, value)
const oldLine = !model.pointA || !model.pointB ? null : [model.pointA, model.pointB]
const line = buildLine(value)
if (dirtyLine(oldLine, line)) {
@@ -310,7 +305,7 @@ function setModelValue(model, value) {
model.pointB = line[1]
}
}
console.log('setModelValue end', oldModel, value, model)
// console.log('setModelValue end', oldModel, value, model)
}
@@ -318,7 +313,7 @@ function dirtyLine(a, b) {
const result = a === b ? false :
a === null && b !== null || a !== null && b === null ||
a[0].time !== b[0].time || a[0].price !== b[0].price || a[1].time !== b[1].time || a[1].price !== b[1].price
console.log('dirtyLine', result, a, b)
// console.log('dirtyLine', result, a, b)
return result
}